Skip to content

Instantly share code, notes, and snippets.

@sakurai-youhei
Created June 12, 2017 04:40
Show Gist options
  • Save sakurai-youhei/a0291e1e7f8130edaa0cf74661f97a62 to your computer and use it in GitHub Desktop.
Save sakurai-youhei/a0291e1e7f8130edaa0cf74661f97a62 to your computer and use it in GitHub Desktop.
Export private key from *.pfx file (PKCS12) into PEM format using pyOpenSSL
from OpenSSL import crypto
with open("path/to/cert.pfx", "rb") as pfx:
cert = crypto.load_pkcs12(pfx.read())
pkey = cert.get_privatekey()
with open("path/to/pkey.pem", "wb") as pem:
pem.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment