简体   繁体   中英

M2Crypto.EVP.EVPError: Unable to read private key in function pkey_read_pem

I have this annoying M2Crypto error:

Traceback (most recent call last): File "/Work/pythonWork/pkpass/test.py", line 18, in <module> smime.load_key(str(keypemPath), pemPath,callback=passwordCallback) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/M2Crypto/SMIME.py", line 163, in load_key self.pkey = EVP.load_key(keyfile, callback) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/M2Crypto/EVP.py", line 395, in load_key cptr = m2.pkey_read_pem(bio.bio, callback) M2Crypto.EVP.EVPError: Unable to read private key in function pkey_read_pem.

My code:

def passwordCallback():
return "123456"

smime = SMIME.SMIME()
wwdrcert = X509.load_cert(wwdrpemPath)
stack = X509_Stack()
stack.push(wwdrcert)
smime.set_x509_stack(stack)
smime.load_key(str(keypemPath), pemPath,callback=passwordCallback)
  • My Python Version is:3.6
  • My openssl Version is:OpenSSL 1.0.2p
  • My M2Crypto Version is:0.30.1

This seems to be a bug in M2Crypto (see https://gitlab.com/m2crypto/m2crypto/-/issues/260 ).

Please try to cast the password to a Python bytes object:

def passwordCallback():
    return bytes("123456", "ascii")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM