Post Script Secret Key Decryption

lonesoac01
Giga Guru

Hello all,

 

I can manually decrypt the encryptedSecret property from an API endpoint with Postman using the Post-request Script.  How can I do this with ServiceNow?

 

var jsonData = JSON.parse(responseBody);
var newencryptedSecret = jsonData.encryptedSecret;
var bytes = CryptoJS.AES.decrypt(newencryptedSecret, key);
var newSecret = bytes.toString(CryptoJS.enc.Utf8);

console.log("here's new Secret");
console.log(newSecret);

 

1 REPLY 1

Tanushree Maiti
Kilo Patron

Try this one,  Same kind of requirement we have implemented. 

 

This is working fine for us.

 

Create a sys_properties with type password.

 

Update your value . After save , value will be encrypted.  //Using fix script /other script like  script include ->call from flow ,decrypt it  as per your requirement.

 

Sample code :

 

// Get the encrypted value from the system property
var encryptedPassword = gs.getProperty('my_encrypted_password_property');
// Create a new GlideEncrypter object
var encrypter = new GlideEncrypter();
// Decrypt the value
var decryptedPassword = encrypter.decrypt(encryptedPassword);
// Now you can use the decryptedPassword variable
gs.info('The decrypted password is: ' + decryptedPassword);

 

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: