Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base64 Encoding for multi Variables

Tags:

postman

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

like image 934
Ronen Noimark Avatar asked Mar 20 '18 09:03

Ronen Noimark


1 Answers

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 Request

Postman Console output:

Postman Console

This is probably not the exact solution that you need but hopefully this brings you closer to achieving what you need to do.

like image 115
Danny Dainton Avatar answered Sep 21 '22 18:09

Danny Dainton