CF DESEDE encrypt() 密钥长度问题
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我唯一觉得奇怪的是你正在使用的算法值。也许试试这个?
我不知道
/CBC/NoPadding
设置是否是您想要的,但我认为它们不会在算法参数中被允许。The only thing that seems off to me is the algorithm value you're using. Maybe try this?
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.一般来说,当使用其他语言提供的密钥时,您必须对其进行一些操作才能将其转换为 Base64。
尝试这个关键参数:
但是,为了让这个对我有用,输入字符串需要是 8 字节的倍数(因为您指定了 NoPadding),并且 IV 也需要是 8 字节的倍数。
所以,这最终对我有用——不确定你是否能够在另一端解密它,不过,他们指定的 IV 是否真的是你在那里列出的。
无 IV 也能正常工作(显然,输出不同):
如果您已经获得了 Hex IV,那么您可以这样使用它:
希望这是足够的信息来帮助您上路!
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:
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.
No IV also worked as well (with different output, obviously):
If you've been given a Hex IV, then you can use it as such:
Hopefully this is enough info to get you on your way!