【发布时间】:2012-10-06 08:33:30
【问题描述】:
我想用 PyCrypto 在 python 中加密一些数据。
但是在使用key = RSA.importKey(pubkey) 时出现错误:
RSA key format is not supported
密钥是通过以下方式生成的:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.key -out mycert.pem
代码是:
def encrypt(data):
pubkey = open('mycert.pem').read()
key = RSA.importKey(pubkey)
cipher = PKCS1_OAEP.new(key)
return cipher.encrypt(data)
【问题讨论】:
-
谷歌搜索的第一个响应:stackoverflow.com/questions/10569189/…
-
@tMC 不适用于我,我使用证书,而不是公钥文件。
标签: python openssl rsa pycrypto