201 views

Description

Non-ASCII characters are not being decrypted correctly by GlideEncrypter() API (for example, £ becomes ᅡᆪ).

Steps to Reproduce

 

Execute the following script:

var message = [];
var encr = new GlideEncrypter();
var clearString = 'serviceà';
var encrString = encr.encrypt(clearString);
var decrString = encr.decrypt(encrString);

message.push('******results******');
message.push('clear text: ' + clearString);
message.push('encrypted text: ' + encrString);
message.push('decrypted text: ' + decrString);

gs.log(message.join('\n'));


Results

******results******
clear text: serviceà
encrypted text: +5GUYgT+2VcjQ4HRApyUfw==
decrypted text: serviceᅢᅠ



Workaround

If you are able to upgrade, review the Fixed In field to determine the versions that have a permanent fix.

You can transform the current non-ASCII characters into ASCII before encrypting, then convert them back after decrypting. For example, using the same scenario as in the Steps to reproduce section, the following script transforms the characters into Base64, then converts them back on decrypting.

 

var message = [];
var encr = new GlideEncrypter();
var clearString = 'serviceà';
var encrString = encr.encrypt(clearString);
var decrString = encr.decrypt(encrString);

message.push('******results******');
message.push('clear text: ' + clearString);
message.push('encrypted text: ' + encrString);
message.push('decrypted text: ' + decrString);

message.push('******with the workaround******');

var fixencrString = encrypt2(clearString);
var fixdecrString = decrypt2(fixencrString);

message.push('encrypted text fixed: ' + fixencrString);
message.push('decrypted text fixed: ' + fixdecrString);

gs.log(message.join('\n'))



// These functions can be stored on a script include
//

// Recommended function to move original values to ASCII base64
function encrypt2(a) {
    if (GlideStringUtil.nil(a)) 
return ""; var b = new GlideEncrypter(); if (isAscii(a))
return b.encrypt(a); a = "#" + GlideStringUtil.base64Encode(a); return b.encrypt(a) } // Recommended function to move ASCII base64 characters to original values function decrypt2(a) { if (GlideStringUtil.nil(a))
return ""; a = new GlideEncrypter().decrypt(a); "#" == a.substring(0, 1) && (a = GlideStringUtil.base64Decode(a.substring(1))); return a } function isAscii(a) { if ("string" !== typeof a) return !1; for (var b = 0; b < a.length; b++) if (127 < a.charCodeAt(b)) return !1; return !0 };

 

RESULT

*** Script: serviceà
*** Script: +5GUYgT+2VcjQ4HRApyUfw==
*** Script: serviceᅢᅠ
*** Script: encfix:AjHidKhH/2I3XojB9XM6+Q==
*** Script: decfix:serviceà


Related Problem: PRB718580

Seen In

Fuji Patch 13 Hot Fix 1

Fixed In

Jakarta

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2018-04-09 02:29:26
Published:2017-10-02