Coldfusion加密/解密问题 [英] Coldfusion Encryption/Decryption issue

查看:214
本文介绍了Coldfusion加密/解密问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近为我的公司使用ColdFusion 9做了一个网站。我遇到的问题是使用ColdFusion加密/解密功能。在我解密的某些字符串,我得到这些奇怪的特殊字符出现。

I recently did a website for my company using ColdFusion 9. The issue I am having is with the ColdFusion encryption/decryption function. On certain strings that I decrypt I get these weird special characters that show up.

示例:

MK / _0 ---加密字符串输出

MK/_0 <---Encrypted String Outputted

#5& z < ---解密字符串输出

�#5&z <---Decrypted String Outputted

我不知道为什么会发生这种情况(只有某些字符串被解密)。

I'm not sure why this is happening (and only on certain strings that get decrypted).

代码:

<cfset ccNum = decrypt(getCCInfo.CUST_CARDNUMBER,myKey)>


推荐答案

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

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

这篇关于Coldfusion加密/解密问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆