且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Coldfusion加密/解密问题

更新时间:2023-09-11 22:36:22

好,首先,通过不指定您正在使用非常差的加密的加密算法。所以你需要解决这个问题。第二,你应该使用一些编码,使你的加密存储更可靠。

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