Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman RSA Encryption

Tags:

rsa

postman

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

like image 368
mad_fox Avatar asked Mar 19 '18 20:03

mad_fox


1 Answers

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
like image 149
joliva Avatar answered Sep 22 '22 01:09

joliva