我想用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