正确的参数以传递给Coldfusion 8(或10)中的AES加密 [英] Correct Parameters to pass to Encrypt AES in Coldfusion 8 (or 10)

查看:99
本文介绍了正确的参数以传递给Coldfusion 8(或10)中的AES加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有(这不起作用b / c十六进制可能是错误的,并且密钥和IV转换不正确):

So I have (this doesn’t work b/c hex is probably wrong and the key and the IV are not converted correctly):

(aesKey和aesIV由第三方提供的十六进制字符串)

(aesKey and aesIV are provided as hex strings from Third Party)

它们看起来像这样(虽然不一样,但是应该足以与我替换键中的某些值,因此它们不是完全相同:

They look something like this (not the same but should be enough to work with I replaced some values in the keys so they aren’t exactly the same:

<cfparam name="aesKey" default="C20648780E8843795325F3BA5EC43183C8BFA2D26B5470BC309ED5BA6B142EFA"/>
<cfparam name="aesIV" default="A53F0A6E6972A0095CFFDBE4F47C3CF8"/>

<cfset token = Encrypt(encryptString, aesKey, "AES/CBC/PKCS5Padding", "hex", aesIV)>

错误是:

指定的密钥对此加密无效:无效的密钥大小或默认参数。

(我也不确定十六进制是对的)

(I’m also not sure "hex" is right)

我也有第三方提供的


第三方为AES加密使用以下参数:

块长度256bit

填充PKCS7

密码模式CBC

密钥长度256bit(待由第三方以十六进制格式提供)

初始化矢量长度128位(由第三方以十六进制格式提供)

Third Party uses the following parameters for AES encryption:
Block Length 256bit
Padding PKCS7
Cipher mode CBC
Key Length 256bit (to be provided by Third Party in hexadecimal format)
Initialization Vector Length 128bit (to be provided by Third Party in hexadecimal format)

秘密(专用)密钥和初始化向量用于对纯文本令牌执行AES加密。然后,将加密的字符串传递给第三方SSO流程,在此使用匹配的密钥和初始化向量对其进行解密。

The secret (private) key and the initialization vector are used to perform AES encryption on the plaintext token. The encrypted string is then passed to Third Party SSO process where it is decrypted with the matching key and initialization vector.

但这不是我想对的内容(它确实想要一个字符串,这只是我传递的字符串是错误的)

But that’s where I’m guessing (it does want a string it’s just the string I’m passing is wrong)

我知道我已经接近了,并且我确实有一个使它工作所需的一切解决方案(其中我从CF转到.net并使用提供的示例代码),但我不想这样做。 。 。但是我有。 (这是我第二次从语言B重新回到语言A,因为我有工作原理)

I know I’m close and I do have a "Whatever it takes to make it work" solution (where I go from CF to .net and use the sample code provided) but I don’t want to do that, . . . but I do have it. (This would be the second time I went from language B back to language A because I have something that works)

推荐答案

有为了使其正常工作,您必须做一些事情:

There are a few things you must do in order to get it work:


  1. 默认情况下,AES的密钥仅限于128位。要使用更大的密钥(例如256位),必须首先安装(JCE)用于Java 6的无限强度管辖权策略文件,或 Java 7 / Java 8 (取决于您的JRE版本)。将它们复制到您的 / lib / security / 目录中。 (注意:如果您安装了多个JVM,请确保以正确的jar(即CF Administrator中列出的那个)更新jar。然后重新启动CF服务器。

  1. 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 将密钥从十六进制转换为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)

这篇关于正确的参数以传递给Coldfusion 8(或10)中的AES加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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