我想用PyCrypto加密python中的一些数据.
但是我在使用时遇到错误key = RSA.importKey(pubkey):
RSA key format is not supported
Run Code Online (Sandbox Code Playgroud)
密钥生成时:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.key -out mycert.pem
Run Code Online (Sandbox Code Playgroud)
代码是:
def encrypt(data):
pubkey = open('mycert.pem').read()
key = RSA.importKey(pubkey)
cipher = PKCS1_OAEP.new(key)
return cipher.encrypt(data)
Run Code Online (Sandbox Code Playgroud)