I have a list of 3 environment variables that I want to bind and encode them (Key +value) in base64. fro examples, the 3 Variable now are stored as key-value variables and what i need to have is a base64 encode on this: { "VAR1": "313", "VAR2": "33344", "VAR3": "rovkssj", } I guess that should use the script to create the json and encode it.
appreciate your help Ronen
Postman uses the built-in module CryptoJS
. This could be used to get you close to a solution.
If you add this into the Pre-request Script
or Tests
tab and send a request, you will see the output of the Base64 conversation in the Postman Console. In the example I'm getting the 'VAR1' environment variable
and using this as the value to convert.
var CryptoJS = require("crypto-js")
//Encrypt
var rawStr = CryptoJS.enc.Utf8.parse(pm.environment.get('VAR1'))
var base64 = CryptoJS.enc.Base64.stringify(rawStr)
console.log(`Encrypted value: ${base64}`)
//Decrypt
var parsedWord = CryptoJS.enc.Base64.parse(base64)
var parsedStr = parsedWord.toString(CryptoJS.enc.Utf8)
console.log(`Decrypted value: ${parsedStr}`)
Postman Console output:
This is probably not the exact solution that you need but hopefully this brings you closer to achieving what you need to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With