I'm attempting to using CryptoJS to decrypt a string, provided a 64 character string from SiteMinder.
The decrypted string looks like:
8yi6XwyLPZq%2FNjV9fmoyHYtC2UUS48KlpPLMl063gPwDDLJYkLeUFAwC8hTcXrPJkShbjJTShlLUoh2y17kwOA%3D%3D
And the key provided to me is a 64-character Hex string, like so: B55E3CE5E4E335D61E3224B2EAAA79E68AFF43FFAAA85A9D4F2BA07618DF2D67
After the information is decrypted, it should present a string that shows something like:
term1;term2
The JavaScript code I am using to decrypt with CryptoJS looks like:
CryptoJS.AES.decrypt(
encryptedValue,
64CharacterKeyProvidedAbove
).toString();
However, the decrypted value isn't coming back as expected. I've read some information about providing an IV to use a pre-defined key, but I don't have any information, only the key used when SiteMinder encrypts information from the database it is connected to.
Do I need to change the way I'm using CryptoJS?
Assuming you mean encrypted string looks like 8yi6XwyLPZq%2FNjV9fmoyHYtC2UUS48KlpPLMl063gPwDDLJYkLeUFAwC8hTcXrPJkShbjJTShlLUoh2y17kwOA%3D%3D
.
And given that encryption is AES256/CBC/PKCS7.
We can make these observations:
=
, and Base64 often ends with =
)So we can decrypt it with CryptoJS like this:
var encrypted = CryptoJS.enc.Base64.parse(decodeURIComponent(encryptedStr));
var key = CryptoJS.enc.Hex.parse(hexKey);
var iv = CryptoJS.enc.Hex.parse(CryptoJS.enc.Hex.stringify(encrypted).substr(0, 32));
var ciphertext = CryptoJS.enc.Hex.parse(CryptoJS.enc.Hex.stringify(encrypted).substr(32));
var plaintext = CryptoJS.AES.decrypt({ciphertext: ciphertext}, key, {iv: iv});
Here's a working DEMO on jsFiddle.
Result:
SERLOGINNAME=T6ATD1F;password=QWERTY!8;