The CreatorCon Call for Content is officially open! Get started here.

Copying Encrypted Field Value

vidhya_mouli
Giga Sage

I have a field sn which is encrypted. I want to copy this field value into another form.

 

This is the Script Include:

 

var EncryptionUtils = Class.create();
EncryptionUtils.prototype = {
    initialize: function() {
    },

	getDecryptedValue: function(encryptedValue) {
        var encrypter = new GlideEncrypter();
        return encrypter.decrypt(encryptedValue);
    },
	
    type: 'EncryptionUtils'
};

 

 

And this is the script (which is part of a UI Action):

 

	var ga = new GlideAjax('EncryptionUtils');
	ga.addParam('sysparm_name', 'getDecryptedValue');
	ga.addParam('sysparm_encrypted_value', sn); // Pass the encrypted value to the server
	ga.getXMLAnswer(function(response) {
    var decryptedValue = response;
    // Now you can use the decrypted value as needed
    dialog.setPreference("sysparm_sn", decryptedValue);

 

 

However this is not working. Any suggestions on how to make it work?

1 REPLY 1

Mohan raj
Mega Sage

Hi @vidhya_mouli,

 

The encrypted fields has two field classes there are password (1  Way Encrypted) and password (2 Way Encrypted)

Mohanraj_0-1700756808449.png

 

the  GlideEncrypter() method  won't works for password (2 Way Encrypted) field type. I tried with password (1 Way Encrypted) able to encrypt and decrypt the values stored in this field.

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.