Postman RSA Encryption
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
mad_fox
Updated on August 17, 2022Comments
-
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:
Call a REST API that returns an RSA public key
Store the RSA public key in a variable
Utilize that public key to encrypt an value in the following request before sending
-
SimMac over 5 yearsDoes this still work for you? Even after
eval
-ing the forge.js, I getReferenceError: forge is not defined
. -
joliva over 4 yearsI have add this exmaple to the postman collection in the library here github.com/joolfe/postman-util-lib/tree/master/postman
-
steve y over 4 yearsHow do I make use of this JSON you have shared on github in the previous comment?
-
joliva over 4 yearsHi 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 over 3 yearsit 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 over 2 yearsWhat is the fileContent? Is it the .pem file?