Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python p12 to pem

Tags:

python

pem

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?

like image 956
ab1127 Avatar asked May 08 '14 20:05

ab1127


People also ask

Is P12 the same as PEM?

PKCS12 - A Microsoft private standard that was later defined in an RFC that provides enhanced security versus the plain-text PEM format. This can contain private key and certificate chain material. Its used preferentially by Windows systems, and can be freely converted to PEM format through use of openssl.

Is a PEM file pkcs12?

PEM certificates are not supported, they must be converted to PKCS#12 (PFX/P12) format.


1 Answers

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.

like image 138
DIDoS Avatar answered Oct 20 '22 23:10

DIDoS