Ruby 中的 Rijndael 加密
我对加密完全陌生,所以这个问题可能是微不足道的 - 然而,我不得不用谷歌搜索 2 个小时才能理解基本术语,所以请耐心等待。
我需要发送的字符串是加密 JSON 对象的 Base64 编码字符串。这是他们发给我的规范:
- 加密方法:Rijndael
- 密码模式:CBC
- 填充模式:PKCS7
- 我们将为您提供自定义 Base64Encoded 密钥和 IV。
我检查了 crypt 的 Rijndael 算法,但我不知道将 IV 插入哪里...不确定 CBC 和 PKCS7 是否是默认的 - 如果不是,我也不知道如何更改这些...
那么:
- 可以轻松修改 crypt 来支持这些东西吗?
- 也许它确实已经支持它了,只是我完全缺乏密码知识不允许正确使用?
- 如果以上都不是,是否可以在 Ruby 中执行此操作?
I am totally new to encryption, so this question might be trivial - however, I had to google for 2 hours to understand even the basic terms, so bear with me.
The string I need to send is a Base64 Encoded String of an encrypted JSON object. Here's the spec they sent me:
- Encryption Method: Rijndael
- Cipher Mode: CBC
- Padding Mode: PKCS7
- We will provide you with a custom Base64Encoded Key and IV.
I checked out crypt's Rijndael algorithm, but I don't see where to plug the IV into... Not sure if CBC and PKCS7 are default - if they aren't, I don't know how to change these either...
So:
- Can be crypt easily modified to support this stuff?
- Maybe it does support it already as-it-is, just my total lack of cryptographic knowledge doesn't allow for a proper use?
- If neither of the above, is it possible to do this in Ruby?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我非常怀疑他们是否真的使用 Rijndael。他们可能使用 AES(这是 Rijndael 的子集,具有固定的 128 位块大小和只有三种标准化密钥大小(128,192 和 256 位))。如果没有他们提供块大小和密钥大小,您无论如何都无法确定,您可能会假设 AES-128,但他们的规范充其量是不完整的。
IV 与密码算法无关,而是与链接模式相关,在您的例子中是 CBC。
AES、CBC、PKCS7 可通过 OpenSSL 在 Ruby 中使用,应该不会太麻烦。
编辑:认为他们使用 Rijndael 的人让我认为他们使用 .NET,在这种情况下,这个问题应该可以解决您的问题: 如何在 ruby 中解码 Rijndael(在 VB.net 中编码)
I pretty much doubt they really use Rijndael. They likely use AES (which is is subset of Rijndael with fixed 128 bits block size and only three standardized key size (128,192 and 256 bits)). Without them supplying blocksize and keysize you cannot be sure anyway, you can likely assume AES-128, but their spec is incomplete at best.
The IV is not related to the cipher algorithm but to the chaining mode, in your case CBC.
AES, CBC, PKCS7 are available in Ruby via OpenSSL, shouldn't be too much trouble.
Edit: people thinking they use Rijndael make me think they use .NET, in which case that question should solve your issues : How to decode Rijndael in ruby (encoded in VB.net)
Crypt::Rijndael
这包括在内现在在 ruby 中,可以轻松解密 Rijndael。
Crypt::Rijndael
This is included in ruby now and can do the decryption of Rijndael easily.