Python ASN1 Parse
In this post, we will learn how to parse certificate or pem encoded certificate in ASN1 format in python programming language. To parse certificate in ASN1 we will use python module pyasn1.
If you do not have SSL/TSL certificate you can copy certificate form here and save it in cert.pem file.
In this post, we will learn how to parse certificate or pem encoded certificate in ASN1 format in python programming language. To parse certificate in ASN1 we will use python module pyasn1.
If you do not have SSL/TSL certificate you can copy certificate form here and save it in cert.pem file.
# import required module
from pyasn1_modules import pem, rfc2459
from pyasn1.codec.der import decoder
# read pem TLS/SSL certificate
substrate = pem.readPemFromFile(open('cert.pem'))
# decode certificate in ASN1
cert = decoder.decode(substrate, asn1Spec=rfc2459.Certificate())[0]
# pretty print ASN1 decoded certificate
print(cert.prettyPrint())
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Comments
Post a Comment