We are encrypting a string using Crypto js library.
And we want to decrypt that encrypted string using Crypto apex class. But unfortunately, that is not working.
JS Code
CryptoJS.AES.encrypt('123', '1234567887654321').toString();
Apex Code
Crypto.decryptWithManagedIV('AES128', Blob.valueOf('1234567887654321'), Blob.valueOf(encryptedStringViaCryptoJS));
This is giving below error in Salesforce when we execute above code in Developer Console
System.SecurityException: last block incomplete in decryption
Any idea what we are missing?
Best Answer
This article may help you: https://blog.enree.co/2019/05/salesforce-handle-encryption-and-decryption-with-apex-crypto-class-and-crypojs.html
Key point from SF docs:
Key point from the article:
Basically, here is the algorithm:
base64Secret
:base64Secret
, you can run command: