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)
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.