我想用PyCrypto加密python中的一些数据。如何在PyCrypto中使用X509证书?
但是我使用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)
在谷歌搜索首度回应:http://stackoverflow.com/questions/10569189/how-to-read-a-rsa-public-key-in-pem-pkcs1-format-in-python – tMC
@tMC不适用于我,我使用certificat e,而不是公钥文件。 – eshizhan