在 RSA 算法中,规定明文大小必须小于或等于( key 大小 - 11)。
为什么会这样。那个 11 实际上是什么?
最佳答案
这只是使用 PKCS1 填充时的要求。 “裸”RSA 虽然不安全,但可以执行长度达到 key 大小的操作,并且 OAEP 填充取决于您使用的哈希算法。
来自the PKCS1 spec :
Steps:
1. Length checking: If mLen > k - 11, output "message too long" and
stop.
2. EME-PKCS1-v1_5 encoding:
a. Generate an octet string PS of length k - mLen - 3 consisting
of pseudo-randomly generated nonzero octets. The length of PS
will be at least eight octets.
b. Concatenate PS, the message M, and other padding to form an
encoded message EM of length k octets as
EM = 0x00 || 0x02 || PS || 0x00 || M.
据此,明文前面至少添加了 11 个字节。 0x00 和 0x02,然后是 PS,其长度为“至少八个八位字节”,然后是 0x00。所以 3 + 8 = 11。
关于algorithm - RSA算法查询报文大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20114560/