3

I'm currently getting a 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 extraction calling the commands on the terminal from python but I would prefer to do it with python libraries.

I looked for examples with pyopenssl but I didn't find something really similar to what I'm trying to achieve.

How can I achieve the same result using python libraries?

0

2 Answers 2

4

Have a look at cryptography.io. There's DER certificate loading and private key loading supports PKCS#8 format.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I'll check it out
0

Since using python cryptography didn't work for me I looked for an alternative package.

I found using chilkat is exactly what I needed. It has pkcs8 support and it's really fast.

My code is as follows

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.