小编esh*_*han的帖子

如何在PyCrypto中使用X509证书?

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

python openssl rsa pycrypto

21
推荐指数
1
解决办法
3万
查看次数

标签 统计

openssl ×1

pycrypto ×1

python ×1

rsa ×1