There seem to be two problems:
CryptoJS does not use your variable as key . As @ Miguel-F mentioned, when you pass a string, "it is treated as a key phrase and used to get [the actual key and IV . " Both are randomly generated, so your encrypted result keeps changing. But more importantly, this means that CryptoJS uses a completely different key than the one in your CF code, which is why decrypt () fails. (At least that's part of the reason ...)
The second problem is that in addition to the "AES" algorithm, there are two more encryption parameters that must correspond: mode and the complementary scheme . Although CryptoJS and ColdFusion use the same default values ββfor the padding scheme, the βmodesβ are different:
You need to make sure that all three settings are the same on both sides. Try using CBC mode in CF, as it is safer in any case than ECB. Note: this requires adding an IV value.
CF Code:
<cfset encrypted = "J2f66oiDpZkFlQu26BDKL6ZwgNwN7T3ixst4JtMyNIY="> <cfset rawString = " max.brenner@google.com.au "> <cfset base64Key = "MTIzNDU2NzgxMjM0NTY3OA=="> <cfset base64IV = "EBESExQVFhcYGRobHB0eHw=="> <cfset ivBytes = binaryDecode(base64IV, "base64")> <cfoutput> #decrypt(encrypted, base64Key, "AES/CBC/PKCS5Padding", "base64", ivBytes)# </cfoutput>
CryptoJS: (adjusted source example)
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script> <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script> <script> var text = "#rawString#"; var key = CryptoJS.enc.Base64.parse("#base64Key#"); var iv = CryptoJS.enc.Base64.parse("#base64IV#"); var encrypted = CryptoJS.AES.encrypt(text, key, {iv: iv}); console.log(encrypted.toString()); var decrypted = CryptoJS.AES.decrypt(encrypted, key, {iv: iv}); console.log(decrypted.toString(CryptoJS.enc.Utf8)); </script>
Edit:
All that said, what do you mean by the client, "has no choice but to use CryptoJS to perform encryption"? Why can't they use server-side encryption? I am not an expert on encryption, but I perform encryption in javascript, and exposing the key on the client does not sound impeccable to start with ...
Leigh source share