CF DESEDE encrypt() 密钥长度问题

发布于 2024-09-18 10:19:38 字数 349 浏览 5 评论 0原文

我正在尝试使用 ColdFusion encrypt() 和第三方提供的密钥来加密字符串,如下所示:

encrypteded = encrypt('theString', 'FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF', 'DESEDE/CBC/NoPadding', 'BASE64', ToBase64('0'));

我得到:

“指定的密钥不是此加密的有效密钥:密钥算法错误,应为 DESede。”

在编码/解码方面我必须对该密钥执行什么操作才能将其转换为正确的格式?

I am trying to encrypt a string using ColdFusion encrypt() with a 3rd party provided key like this:

encrypteded = encrypt('theString', 'FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF', 'DESEDE/CBC/NoPadding', 'BASE64', ToBase64('0'));

I get:

"The key specified is not a valid key for this encryption: Wrong key algorithm, expected DESede."

What do I have to do to this key in terms of encoding/decoding to get it into the right format?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

又爬满兰若 2024-09-25 10:19:39

我唯一觉得奇怪的是你正在使用的算法值。也许试试这个?

encrypteded = encrypt('theString', 'FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF', 'DESEDE', 'BASE64', ToBase64('0'));

我不知道 /CBC/NoPadding 设置是否是您想要的,但我认为它们不会在算法参数中被允许。

The only thing that seems off to me is the algorithm value you're using. Maybe try this?

encrypteded = encrypt('theString', 'FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF', 'DESEDE', 'BASE64', ToBase64('0'));

I don't know if the /CBC/NoPadding settings will be what you want, but I don't think they will be allowed in the algorithm argument.

谁与争疯 2024-09-25 10:19:38

一般来说,当使用其他语言提供的密钥时,您必须对其进行一些操作才能将其转换为 Base64。

尝试这个关键参数:

 ToBase64(BinaryDecode('FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF','hex'))

但是,为了让这个对我有用,输入字符串需要是 8 字节的倍数(因为您指定了 NoPadding),并且 IV 也需要是 8 字节的倍数。

所以,这最终对我有用——不确定你是否能够在另一端解密它,不过,他们指定的 IV 是否真的是你在那里列出的。

 encrypteded = encrypt('theStrin', ToBase64(BinaryDecode('FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF','hex')), 'DESEDE/CBC/NoPadding', 'BASE64', ToBase64('0000'));

无 IV 也能正常工作(显然,输出不同):

encrypteded = encrypt('theStrin', ToBase64(BinaryDecode('FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF','hex')), 'DESEDE/CBC/NoPadding', 'BASE64');

如果您已经获得了 Hex IV,那么您可以这样使用它:

encrypteded = encrypt('theStrin', ToBase64(BinaryDecode('FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF','hex')), 'DESEDE/CBC/NoPadding', 'BASE64', BinaryDecode("7fe8585328e9ac7b","hex"));

希望这是足够的信息来帮助您上路!

Generally, when using provided keys from other languages, you have to do a little gymnastics on it to get it into Base64.

Try this for the key argument:

 ToBase64(BinaryDecode('FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF','hex'))

But, to make this work for me, the input string needed to be a multiple of 8 bytes (because you're specifying NoPadding), and the IV needed to also be a multiple of 8 bytes.

So, this ended up working for me - not sure if you'll be able to decrypt it on the other end, tho, if the IV they're specifying is really what you've got listed there.

 encrypteded = encrypt('theStrin', ToBase64(BinaryDecode('FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF','hex')), 'DESEDE/CBC/NoPadding', 'BASE64', ToBase64('0000'));

No IV also worked as well (with different output, obviously):

encrypteded = encrypt('theStrin', ToBase64(BinaryDecode('FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF','hex')), 'DESEDE/CBC/NoPadding', 'BASE64');

If you've been given a Hex IV, then you can use it as such:

encrypteded = encrypt('theStrin', ToBase64(BinaryDecode('FD52250E230D1CDFD5C2DF0D57E3E0FEFD52250E230D1CDF','hex')), 'DESEDE/CBC/NoPadding', 'BASE64', BinaryDecode("7fe8585328e9ac7b","hex"));

Hopefully this is enough info to get you on your way!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文