Created
March 7, 2018 01:24
-
-
Save srialdabaoth/7464f8b65c638baa55c6e08398b4586c to your computer and use it in GitHub Desktop.
PEM Parsing
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
| import json | |
| from asn1crypto import pem, x509 | |
| with open('key.pub', 'rb') as f: | |
| der_bytes = f.read() | |
| if pem.detect(der_bytes): | |
| type_name,headers,decoded_bytes = pem.unarmor(der_bytes) | |
| cert = x509.Certificate.load(decoded_bytes) | |
| print(type_name) | |
| print(headers) | |
| print(decoded_bytes) | |
| headers_s = json.dumps(headers) | |
| decoded_bytes_s = str(decoded_bytes) | |
| with open('test_file.txt', 'w') as f: | |
| # pem_bytes = pem.armor('CERTIFICATE', der_bytes) | |
| f.write(type_name) | |
| f.write(headers_s) | |
| f.write(decoded_bytes_s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment