python3 ValueError: RSA key format is not supported

最近要采用公钥秘钥的方式验证身份,具体就不细说了,这里主要记录再网上查找配置签名和验签过程中遇到的问题,

from Crypto.Hash import SHA
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5 as Signature_pkcs1_v1_5
def sign(data):
    with open('myPrivateKey.pem') as pk:
        key_data = pk.read()
        print(key_data)
    rsaKey = RSA.importKey(key_data, passphrase='123')
    print(rsaKey)
    signer = Signature_pkcs1_v1_5.new(rsaKey)
    digest = SHA.new()
    digest.update(unsign_data)
    sign = signer.sign(digest)
    signature = base64.b64encode(sign)
一直报这个错误  ValueError: RSA key format is not supported

如果你再生成公钥私钥的时候加密了,一定要密码正确

rsaKey = RSA.importKey(key_data, passphrase=b'jy123')
'myPrivateKey.pem'  注意配置好,如果其他程序调用这个方法,接会报错,建议设置绝对路径os.path.dirname实现

你可能感兴趣的:(python3 ValueError: RSA key format is not supported)