Skip to content

Instantly share code, notes, and snippets.

@eaccmk
Last active April 24, 2024 12:42
Show Gist options
  • Save eaccmk/501177b2834a20caa995626849f32ebd to your computer and use it in GitHub Desktop.
Save eaccmk/501177b2834a20caa995626849f32ebd to your computer and use it in GitHub Desktop.
Base64 decoding using postman (Working in Postman v7.34.0 version)
const base64EncodedString = "YWJjZDEyMzQ=" ; // abcd1234
console.log("INPUT >> ",base64EncodedString," <<");
if(!base64EncodedString.length > 0) {
pm.test("FAIL ", () => {throw new Error(" 'base64EncodedString' can not be empty !!")});
}else{
try{
var wordArray = CryptoJS.enc.Base64.parse(base64EncodedString);
var decodedString = CryptoJS.enc.Utf8.stringify(wordArray);
console.log("OUTPUT >> ",decodedString," <<");
pm.test(decodedString,function(){});
}catch(e){
pm.test("FAIL", () => {throw new Error("Malformed 'base64EncodedString', please verify the input again.")});
}
}
/*
@uthor : https://medium.com/@eaccmk
@date : 19-10-2020
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment