Sample code for 30+ languages & platforms
Chilkat2-Python

Load Certificate from .cer and Private Key from .pem

See more Certificates Examples

Load a certificate from a .cer and its associated private key from a .pem.

Chilkat Chilkat2-Python Downloads

Chilkat2-Python
import sys
import chilkat2

success = False

cert = chilkat2.Cert()
success = cert.LoadFromFile("C:/certs_and_keys/Certificate.cer")
if (success == False):
    print(cert.LastErrorText)
    sys.exit()

sbPem = chilkat2.StringBuilder()
success = sbPem.LoadFile("C:/certs_and_keys/PrivateKey.pem","utf-8")
if (success == False):
    print("Failed to load private key PEM")
    sys.exit()

success = cert.SetPrivateKeyPem(sbPem.GetAsString())
if (success == False):
    print(cert.LastErrorText)
    sys.exit()

print("The certificate and associated private key are now loaded and ready for signing.")