I'm struggling to decode a piece of AES-256 encrypted base64 coded data in node.js. The data was encoded in Salesforce. I tried various different aes algorithms but without luck.
I'm crypting and encoding the data in the developer console using anonymous APEX using this code.
String clearText = 'the quick brown fox jumps over the lazy dog'; Blob key = Blob.valueOf('abcabcabc1abcabcabc1abcabcabc132'); Blob cipherText = Crypto.encryptWithManagedIV('AES256', key, Blob.valueOf(clearText)); String encodedCipherText = EncodingUtil.base64Encode(cipherText); System.debug(encodedCipherText);
In node I'm trying to decrypt with the following lines. I got the "cryptoStr" from the debug output of the anonymous apex.
var crypto = require('crypto'); algorithm = 'aes-256-cbc', password = 'abcabcabc1abcabcabc1abcabcabc132'; var cryptoStr = 'Q336OpFur65nt1NgGUebbgx5hmwpcH3iUEd4mXq8qVwXL91qpLSaFecgKpsVvQEiT0DOMwK3TpUksPnjbr3wKA=='; var decipher = crypto.createDecipher(algorithm,password); decipher.setAutoPadding(false); var dec = decipher.update(cryptoStr,'base64','utf-8'); dec += decipher.final('utf-8'); console.log('Decrypted content: ' + dec);
Any ideas are most welcome!