0

I am trying to encrypt the string in coldfusion and decrypt in javascript, i have seen examples of happening in Node.JS and node is javascript, but i am trying to do in raw javascript format and i tried something here but i am sure i am missing something big

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js" integrity="sha256-/H4YS+7aYb9kJ5OKhFYPUjSJdrtV6AeyJOtTkw6X72o=" crossorigin="anonymous"></script>

<cfscript>
enc_string = '7001010000006aaaaaabbbbbb';
myKey = Tobase64("abcdefghijkl1234");
myIV = charsetDecode("abcdefghijkl9876", "utf-8");
uid=encrypt(enc_string,myKey,'AES/CBC/PKCS5Padding','hex',myIV);
writedump(uid);

</cfscript>

<script>
    var decrypted = CryptoJS.AES.decrypt(uid, "7001010000006aaaaaabbbbbb");
    alert(decypted);
</script>

not sure if i did it correctly or not, but this is what i quickly cam eup with

Jianxee
  • 15
  • 4
  • Since the code is not runnable and there's no description of what's wrong with the result, it's difficult to assist. Please take the time to put together a proper [*complete* minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) that others can execute and briefly explain the problem with the result. Also, take a minute to read [the documentation](https://cryptojs.gitbook.io/docs/) which describes using a "Custom Key and IV". Voting to close. – SOS Feb 22 '22 at 04:59
  • this is the working gist https://trycf.com/gist/270d4b0c7b03c6fb92d0c925ba19b3e3/acf2021?theme=monokai – Jianxee Feb 23 '22 at 20:11
  • Why did you switch to using ECB mode? CryptoJS uses CBC by default, so you're mixing modes. Go back to your first example. Take a minute to read the documentation I linked above. It explains how to pass a key and iv. Also you search SO first for [coldfusion] AES CryptoJS. The first page of results contain answers that explain why it's not working https://stackoverflow.com/questions/16600509/aes-encrypt-in-cryptojs-and-decrypt-in-coldfusion and https://stackoverflow.com/questions/34029274/coldfusion-decrypt-wont-work-with-cryptojs-given-final-block-not-properly-padd – SOS Feb 24 '22 at 00:32

0 Answers0