我们有一个用 Coldfusion9 编写的静默登录服务,它接受来自外部系统的加密字符串,然后根据商定的算法/编码设置解密。多年来,这在运行 ASP/JAVA/PHP 的系统上一直没有问题,但是我们现在有一个客户别无选择,只能使用 CryptoJS 来执行加密,而在我的一生中,我无法弄清楚为什么这不会在 Coldfusion 中解密。
我的加密知识并不出色,但我注意到的是,每次我执行加密时,完全相同的字符串/密钥的 CryptoJS 加密密文都会有所不同,而在 Coldfusion/Java 中,我总是可以期待完全相同的加密字符串。我不确定这是否与编码相关,但我之前从未遇到过从任何其他系统接受加密字符串的问题,所以我希望这是我在 CryptoJS 中加密的方式不正确。
<cfoutput>
<!--- Set String and Key --->
<cfset theKey = toBase64("1234567812345678")>
<cfset string = "max.brenner@google.com.au">
<!--- CryptoJS AES Libraries --->
<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>
// Encrypt String using CryptoJS AES
var encrypted = CryptoJS.AES.encrypt("#string#", "#theKey#");
console.log(encrypted.toString());
// Decrypt String using CryptoJS AES
var decrypted = CryptoJS.AES.decrypt(encrypted, "#theKey#");
console.log(decrypted.toString(CryptoJS.enc.Utf8));
</script>
<!--- Coldfusion Decrypt String / FAILS --->
Decrypted: #decrypt(encryptedEmail, "#theKey#", "AES", "BASE64")#
</cfoutput>