更新时间:2023-09-13 19:31:46
默认情况下,您只能使用AES的128位密钥。要使用较大的键(如256位元),您必须先安装(JCE)Java 6的无限制强制管辖权政策文件,或 Java 7 / Java 8 (取决于您的JRE版本)。将它们复制到您的 / lib / security /
目录中。 (注意:如果您安装了多个JVM,请务必更新正确的JVM,即CF管理员列出的JVM。然后重新启动CF服务器。
By default, you are limited to 128bit keys for AES. To use larger keys, like 256bit, you must first install the (JCE) Unlimited Strength Jurisdiction Policy Files for Java 6, or Java 7 / Java 8 (depending on your JRE version). Copy them into your /lib/security/
directory. (Note: If you have multiple JVM's installed, be sure you update the jars in the correct one ie The one listed in the CF Administrator). Then restart the CF server.
Encrypt()
期望键为base64格式。因此,请使用 binaryDecode / Encode 将密钥从hex转换为base64:
Encrypt()
expects keys to be in base64 format. So use binaryDecode/Encode to convert the key from hex to base64:
< cfset base64Key = binaryEncode(binaryDecode(yourHexKey,hex),base64)/>
iv
应为二进制。再次使用binaryDecode转换:
The iv
should be in binary. Again, use binaryDecode to convert it:
< cfset binaryIV = binaryDecode(yourHexIV,hex)/>
完成这些更改后,您的代码应该可以正常工作:
Once you have made those changes, your code should work fine:
Encrypt(encryptString, base64Key, "AES/CBC/PKCS5Padding", "hex", binaryIV)
(尽管标题中有过时的版本,但我发现这篇关于强加密的文章是解决加密问题的绝佳参考)
(Despite the antiquated version in the title, I have found this article on strong encryption to be a great reference for troubleshooting encryption issues)