save URL at step 1 in global Varaible with name “jsEncrypt”;
In Pre-request Script, write script as below:
navigator = {};
window = {};
pm.sendRequest(pm.globals.get("jsEncrypt"), (err, res) => {
var text = res.text();
(new Function(text))();
var jsencrypt = new JSEncrypt.JSEncrypt({
default_key_size: 4096
});
jsencrypt.setKey( "// here is public key" );
var result = jsencrypt.encrypt("// here is you clear value before you want to encrypt");
console.log(CryptoJS.enc.Base64.parse(result).toString());
Could you please help me to execute your code?
I tried to execute your code in the Postmans Pre-request script but it is not working.
It is having a syntax error and when the syntax error is resolved, JSEncrypt is not defined error is coming.
Below is the working code…
window = {};
pm.sendRequest(pm.globals.get(“jsEncrypt”), (err, res) => {
var text = res.text();
(new Function(text))();
var jsencrypt = new window.JSEncrypt;
jsencrypt.setPublicKey("//here is public key");
var result = jsencrypt.encrypt("//here is you clear value before you want to encrypt");
});