【发布时间】:2019-09-09 03:22:37
【问题描述】:
大家好,我在 python 中使用 rsa 模块 import rsa 来加密超过 53 个字节的消息。但似乎rsa.encrypt(message, private_key) 的消息长度限制只有 53 个字节。
>>> rsa.encrypt(b'A'*53, private_key)
b"(\xe9\xbf\xcc?\x18'\xb4Q@\xce\xb5=\xce#\x91\xb3\xe2+QT\\d\xe4\xaf\x07\xdb\x01\xe2\x83\xc6-\xfe\x03\xa5]\x9a\xad\x90\xb1L\xab\xed\xf3zWw\xccM\xa4.Yw!{\xf4\x08\x95\x9ex7\xbb\x9b\xff"
但长度大于 53:
>>> rsa.encrypt(b'A'*54, private_key)
Traceback (most recent call last):
File "<pyshell#216>", line 1, in <module>
rsa.encrypt(b' '*54, s_pub)
File "/usr/local/lib/python3.7/dist-packages/rsa/pkcs1.py", line 172, in encrypt
padded = _pad_for_encryption(message, keylength)
File "/usr/local/lib/python3.7/dist-packages/rsa/pkcs1.py", line 89, in _pad_for_encryption
' space for %i' % (msglength, max_msglength))
OverflowError: 54 bytes needed for message, but there is only space for 53
有什么方法可以让消息加密的时间更长?
【问题讨论】:
-
如果您只使用 128000 位密钥,您可以加密长达 15989 字节的消息。
-
为什么使用 RSA 加密?
标签: python encryption rsa