How to get public key using PyOpenSSL?
public-key, python, x509
Solution
First you can load the certificate like this
from OpenSSL import crypto
#cert is the encrypted certificate int this format -----BEGIN -----END
crtObj = crypto.load_certificate(crypto.FILETYPE_PEM, cert)
pubKeyObject = crtObj.get_pubkey()
pubKeyString = crypto.dump_publickey(crypto.FILETYPE_PEM,pubKeyObject)
print pubKeyString
you will see something like
-----BEGIN PUBLIC KEY-----
....
....
-----END PUBLIC KEY-----
Problem
I'm tring to create python script, that would take PKCS#12 package and print some information contained in x509 certificate and using for this purpouses PyOpenSSL module. So far i want to fetch from certificate public key. But PKey object doesn't have appropriate method. Where can I move out of here ? Any ideas how to get public key ? ``` pfx=open('./1.p12','rb').read() PKCS=crypto.load_pkcs12(pfx) cert=PKCS.get_certificate() PKey=cert.get_pubkey() print PKey <OpenSSL.crypto.PKey object at 0x012432D8> ``` Thanks.