Coldfusion Encryption/Decryption issue

[亡魂溺海] 提交于 2019-12-06 20:38:31

Ok, well first, I have to point out that by not specifying an encryption algorithm you are using very POOR encryption. So you'll need to fix that. Second, you should probably be using some encoding to make your crypto storage more reliable.

So try this code.

<cfset key = generateSecretKey("AES") />

<!--- Set the ciphertext to a variable. This is the string you will store for later deciphering --->
<cfset cipherText = encrypt(plaintext, key, "AES/CBC/PKCS5Padding", "HEX") />

<cfoutput>#cipherText#</cfoutput> 

<!--- Then when you decrypt --->

<cfset decipherText = decrypt(cipherText, key, "AES/CBC/PKCS5Padding", "HEX") />

<cfoutput>#decipherText#</cfoutput>

The above code will use a strong crypto algorithm and will put the ciphertext into a much easier to store format than the gibberish you showed as an example above. That way when you store it, it will be more reliable when you retrieve it again.

Here is an example of what the string will look like:

A51BBB284D6DCCDC17D26FB481584236087C3AB272918E17963BAF749438C06A484922820EDCCD25150732CC5CF8A096
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!