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