Postman RSA Encryption

10,642

I have created a little ¨library¨ to use cryptographic methods in Postman Pre-request and Tests script, RSA is totally supported, have a look to the tutorial here, is very easy to use.

https://joolfe.github.io/postman-util-lib/

Best Regards.

Here is an example of how to RSA encrypt using the 'RSAOAEP' alg:

// RSAOAEP signature example
const pubkey = '-----BEGIN PUBLIC KEY-----\n' +
'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAstXEkU/agbNkQgh6a9DV\n' +
'C/WXGmNy8g+hdTOBhYUk5PfZCwTNt5SCYBLjIPhs2ZRrNuCN3PhwHRQPQOTsS6Nl\n' +
'Bzw+SjPVFBhPcbMHbJWnC87Q5ID/uAuwJjcUQXUTVspwIgfRmHvuuT7w7AYnCNvz\n' +
'B5TuPj2vVH8rij9BXkAHambaeGG7L10MPeUiVU6M0F/QKCJhEWAYGEt4NffSXETx\n' +
'zHSl8nyXxVJfnjxVhnZyZVXTIpLwvRy04hnkAoFexh7npRtnQdsLuIHtaJsm7gFY\n' +
'mxhr3Nxbh9p1pC7fHpJ+jMcxAAhA07WqYf6lOsxXHfPav1FEMX214YTsKTw68xqo\n' +
'DwIDAQAB\n' +
'-----END PUBLIC KEY-----\n'

const fileContent = 'My file content comes here...'
const keyObj = pmlib.rs.KEYUTIL.getKey(pubkey)
const encHex = pmlib.rs.KJUR.crypto.Cipher.encrypt(fileContent, keyObj, 'RSAOAEP')

console.log(encHex)
// will return the hexadecimal encoded, can be converted to many format ussing the library too
Share:
10,642
mad_fox
Author by

mad_fox

Updated on August 17, 2022

Comments

  • mad_fox
    mad_fox almost 2 years

    I would like to utilize postman to test a REST API that requires one of the input fields to be encrypted with RSA encryption.

    I see that postman provides the functionality through require('crypto-js') to encrypt using AES encryption, but I that library does not provide RSA encryption. How can I use post man to automate RSA encryption?

    The flow would work like this:

    1. Call a REST API that returns an RSA public key

    2. Store the RSA public key in a variable

    3. Utilize that public key to encrypt an value in the following request before sending

  • SimMac
    SimMac over 5 years
    Does this still work for you? Even after eval-ing the forge.js, I get ReferenceError: forge is not defined.
  • joliva
    joliva over 4 years
    I have add this exmaple to the postman collection in the library here github.com/joolfe/postman-util-lib/tree/master/postman
  • steve y
    steve y over 4 years
    How do I make use of this JSON you have shared on github in the previous comment?
  • joliva
    joliva over 4 years
    Hi Steve, the JSON are postman collections so you just need to import in your POSTMAN app, as described here learning.getpostman.com/docs/postman/collection-runs/…
  • Oleksandr Kulychok
    Oleksandr Kulychok over 3 years
    it is because postman.setEnvironmentVariable("forgeJS", res.text()); executed in async callback.If ok for you - execute first part in pre-request script. Or use trick from here community.postman.com/t/…
  • Bemojo
    Bemojo over 2 years
    What is the fileContent? Is it the .pem file?