Copy link to clipboard
Copied
I'm working on a Photoshop CES extension and attempting to encrypt data using CryptoJS. This works, except when I convert the encrypted data to a string and then try to decrypt it.
Here's a link to a JS Fiddle that works:
https://jsfiddle.net/davevsdave/atwpbmr5/3/
This same code in ExtendScript Toolkit or running in Photoshop does not return the correct finalResult var. Here's the code I'm running in extendscript, identical to what is in the above JSFiddle (except $.println instead of console.log and an extra line showing that decrypting the obj works):
//JSON from Panel
jsonStr = '{"date":"1563662582633","email":"email@email.com","password":"1234324","uniqueID1":"12345","uniqueID2":"asfdsa-asdfsa-adsfas-sadfsdf-asfsaf\n"}';
//Encrypt Data
var encrypted = CryptoJS.AES.encrypt(jsonStr, 'secret_passcode');
//Convert OBJ to String so I can save it
var encryptedString = encrypted.toString();
$.writeln('encryptedString is ' + encryptedString);
//Decrypt string - DOES NOT WORK IN EXTENDSCRIPT
var decryptedValue1= CryptoJS.AES.decrypt(encryptedString, 'secret_passcode');
$.writeln('decryptedValue1 is ' + typeof decryptedValue1);
//Decrypt OBJ - WORKS IN EXTENDSCRIPT
var decryptedValue2= CryptoJS.AES.decrypt(encrypted, 'secret_passcode');
$.writeln('decryptedValue2 is ' + typeof decryptedValue2);
$.writeln('finalOutput is ' + decryptedValue.toString(CryptoJS.enc.Utf8));
I'm guessing the issue is Extendscript using ES3. Any suggestions on how I can convert the encrypted data to a string (so I can store it as JSON) and then still be able to decrypt it? Or am I going about this the wrong way?
Copy link to clipboard
Copied
Hi Dave,
I'm not sure if this article will help you out, but it might. Let me know if it's useful!
Regards,
Erin F
Copy link to clipboard
Copied
Can you just stay in CEP space the whole time or is there a reason you need to do some of the decryption in ExtendScript? If you need ExtendScript, then yes you'll need a library that's ES3 compatible. I personally like the crypto module built into Node.js for this sort of stuff.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now