Created
December 24, 2014 09:27
-
-
Save akash0x53/564ff30fd584145e5e7d to your computer and use it in GitHub Desktop.
Extract key, certificate from pkcs12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_cert_key(certpath=None): | |
""" | |
Extracts private key & certificate and returns as pem string. | |
params: | |
certpath = Valid P12 certificate file path. | |
returns: | |
(certificate, privatekey) | |
""" | |
import os | |
import getpass | |
import OpenSSL.crypto as crypto | |
assert certpath, None | |
certpath = os.path.realpath(certpath) | |
paswd = getpass.getpass() | |
pk12 = crypto.load_pkcs12(open(certpath).read(), paswd) | |
return crypto.dump_certificate(crypto.FILETYPE_PEM, pk12.get_certificate()),\ | |
crypto.dump_privatekey(crypto.FILETYPE_PEM, pk12.get_privatekey()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment