python - RSA 解密返回额外数据

标签 python encryption cryptography openssl

我可以解密一些通过 openssl 命令行工具加密的数据,但是一些“额外”数据与原始数据一起返回。 我创建了一个像这样的加密文件:

$ echo 这是它>file.txt

$ openssl rsautl -加密 -pubin -inkey public.pem -in file.txt -out crypto.txt

我可以通过以下方式访问原始数据:

from Crypto.PublicKey import RSA
key = open('/tmp/.private.key').read()
rsakey = RSA.importKey(key, 'MyPassphrase')
data = open('/tmp/encrypted.txt', 'rb').read()
original = rsakey.decrypt(data)

但是返回了一些额外的数据,输出如下:

\x02h\x83\xcfx\x84,\xb1\xa6 [...] \xcf5\x9f\xbbG\xf1\x14\xd0\x8d\x1f\xfe\x9c4\xbb\x1aB\xfa\xc3b\xc2\xe0K\x85\xb5\x10y\xe1\x8e\x00this is this\n

我可以避免在解密数据之前接收此原始数据吗?

观察: key 是使用 openssl 工具创建的

谢谢。

最佳答案

您将获得 PKCS#1 v1.5 填充纯文本。您需要先删除 PKCS#1 v1.5 填充。当前您正在执行教科书(或“原始”)RSA 解密,这只不过是模幂运算。尝试使用 PKCS#1 v1.5 功能的类,例如 this one

关于python - RSA 解密返回额外数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29707886/

相关文章:

c++ - 没有对象c++ Crypto Program无法调用成员函数

java - 提高加密 AES android 的速度

python - 如何使用 Python 创建嵌套的 JSON 对象?

python - 追加或添加到特定索引的字符串

python - 在 python 中操作函数输出

encryption - 哪些可打印的 ASCII 字符通常会出现在英文文本中?

python - 我可以为 sklearn SVM 显式设置可能的类列表吗?

java - RSA Cypher VisualBasic 到 Java

C 中的凯撒密码 : can't seem to wrap around the latter letters of the alphabet

java - Java 中所有 UTF-8 字符的维吉尼亚密码