Are openssl commands equivalent in python?
I am currently getting the private key with
openssl pkcs8 -in file.key -inform DER
And for some cer file
openssl x509 -text -inform DER -in file.cer
I can handle the checkout by invoking commands on the terminal from python, but I would rather do it using the python libraries.
I have searched for examples with pyopenssl but I have not found anything similar to what I am trying to achieve.
How can I achieve the same result using python libraries?
source to share
Since using python cryptography didn't work for me, I was looking for an alternative package.
I found the use chilkat
exactly what I needed. It supports pkcs8 and is very fast.
My code looks like this
def get_private_key(filepath, password):
pkey = chilkat.CkPrivateKey()
pkey.LoadPkcs8EncryptedFile(filepath, password)
return pkey.getPkcs8Pem()
def get_certificate_and_serial(filepath):
cert = chilkat.CkCert()
cert.LoadFromFile(filepath)
serial = unhexlify(cert.serialNumber())
return cert.exportCertPem(), serial.decode('utf-8')
Chilkat can be found here
source to share
Have a look at cryptography.io . There Download DER Certificate and Download Private Key supports PKCS # 8 format.
source to share