【发布时间】:2020-12-07 22:03:30
【问题描述】:
尝试导入使用 openssl 创建的 2048 位 RSA 私钥并使用它来加密字符串。关注这个https://cryptobook.nakov.com/asymmetric-key-ciphers/rsa-encrypt-decrypt-examples
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
pr_key = RSA.import_key(open('my_priv_key.pem', 'r').read())
msg = "blah"
encryptor = PKCS1_OAEP.new(pr_key)
encrypted = encryptor.encrypt(msg)
print(encrypted)
错误:
» python encrypt.py
Traceback (most recent call last):
File "encrypt", line 10, in <module>
encrypted = encryptor.encrypt(msg)
File "/python/lib/python3.7/site-packages/Crypto/Cipher/PKCS1_OAEP.py", line 121, in encrypt
db = lHash + ps + b'\x01' + _copy_bytes(None, None, message)
TypeError: can't concat str to bytes
【问题讨论】:
-
这应该可以工作
msg = b"blah" -
同样的错误
标签: python encryption rsa