-
-
Save designgears/0ddf3a3f075a262491e524d47d79b6b3 to your computer and use it in GitHub Desktop.
Convert pfx cert to pem
This file contains 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
import os, sys | |
import contextlib | |
import tempfile | |
import OpenSSL | |
def pfx_to_pem(pfxPath, pfxPassword): | |
with open(os.path.join(os.path.dirname(__file__), '%s.pem'%os.path.basename(pfxPath).split('.')[0]), 'wb') as pem: | |
pfx = open(pfxPath, 'rb').read() | |
p12 = OpenSSL.crypto.load_pkcs12(pfx, pfxPassword) | |
pem.write(OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, p12.get_privatekey())) | |
pem.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, p12.get_certificate())) | |
pem.close() | |
print('Converted to %s!' % pem.name) | |
return 0 | |
if __name__ == '__main__': | |
if len(sys.argv) > 2: | |
print('Usage is %s path/to/pfx!' % sys.argv[0]) | |
sys.exit(1) | |
sys.exit(pfx_to_pem(sys.argv[1], 'switch')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment