Question

I am trying to understand about openssl and certificates and also Python.

So I have this .cert.p12 file. I would like to convert it to .pem format.

I use

openssl -in input.cert.p12 -out output.pem -nodes

This creates the pem file.

How would I do the same process in Python? Take in a p12 file and covert it to a pem format?

Was it helpful?

Solution

Try using an OpenSSL for Python library like "pyOpenSSL"

https://pyopenssl.org/en/stable/api/crypto.html#pkcs12-objects

from OpenSSL import crypto
p12 = crypto.load_pkcs12(file("push.p12", 'rb').read(), [password])

# PEM formatted private key
print crypto.dump_privatekey(crypto.FILETYPE_PEM, p12.get_privatekey())

# PEM formatted certificate
print crypto.dump_certificate(crypto.FILETYPE_PEM, p12.get_certificate())

from here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top