使用 Ruby 的非对称确定性加密 (RSA)
我想知道是否有人知道使用非对称加密算法确定性地加密 Ruby 中的值的方法。
对于大多数用例,人们只关心当您加密“A”时解密时会得到“A”,也就是说您不关心加密值本身。您只关心完整的往返行程。
然而,对于我正在开发的应用程序,我确实需要输出是确定性的。也就是说,我需要使用 RSA 加密某些内容,而不使用变量填充。
当我尝试使用 OpenSSL::PKey::RSA::NO_PADDING 加密值时,会返回错误:
OpenSSL::PKey::RSAError Exception: data too small for key size
有人知道如何使用 RSA 获取确定性加密值吗?
最好的问候,
DBA
I was wondering if anyone knows of a way to deterministically encrypt a value in Ruby using an asymmetric encryption algorithm.
For most use-cases one only cares that when you encrypt 'A' you get 'A' back when you decrypt it, that is you do not care about the encrypted value itself. You only care about the full roundtrip.
However, for an application that I'm developing I really need the output to be deterministic. That is, I need to encrypt something with RSA without a variable padding.
When I attempt to encrypt a value with OpenSSL::PKey::RSA::NO_PADDING
an error is returned:
OpenSSL::PKey::RSAError Exception: data too small for key size
Anyone has an idea on how I can get a deterministic encrypted value using RSA?
Best regards,
DBA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用非随机数据自行填充到适当的密钥长度
You could perform the padding to the appropriate key length yourself with non-random data
此错误来自 crypto/rsa/rsa_none.c
调用来自 rypto/rsa/rsa_eay.c
flen 是消息长度;
tlen
来自:num=BN_num_bytes(rsa->n);
因此,您需要数据与
具有相同的字节长度RSA密钥的N
参数另外,据我所知,您的数据必须小于N(如果视为单个long-long-long二进制数)
This error comes from crypto/rsa/rsa_none.c
Called from rypto/rsa/rsa_eay.c
The
flen
is a message len; and thetlen
is from:num=BN_num_bytes(rsa->n);
So, You need your data have the same byte length as your
N
parameter of RSA keyAlso, as I know, your data must be smaller than N (if considered as single long-long-long binary number)