Convert PEM file to DER Python
In this post , we will learn correct way to convert PEM file or PEM SSL certificate into DER using python OpenSSL module.
Below code using python OpenSSL library to load PEM certificate and converting it into DER format. If you do not have PEM SSL certificate, for test purpose you can copy SSL/TLS certificate from here.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
In this post , we will learn correct way to convert PEM file or PEM SSL certificate into DER using python OpenSSL module.
Below code using python OpenSSL library to load PEM certificate and converting it into DER format. If you do not have PEM SSL certificate, for test purpose you can copy SSL/TLS certificate from here.
import OpenSSL
# load certificate
keyfile = open("/path/to/cert.pem", "r")
# read certificate
cert_file = keyfile.read()
# load certificate buffer
cert_pem = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert_file)
# dump pem certificate into der
cert_der = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_ASN1,cert_pem)
# print der certificate
print (cert_der)
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Rozgardesh (रोजगार देश)
Comments
Post a Comment