CkPython Requires Chilkat v11.8.0+
CkPython
Example: Crypt2.AddPemSource method with PEM text in memory
Demonstrates how to call the AddPemSource method with PEM text that is held in memory.Chilkat CkPython Downloads
import sys
import chilkat
success = False
crypt = chilkat.CkCrypt2()
success = False
# Do public-key decryption (RSA)
crypt.put_CryptAlgorithm("pki")
# ...
# ...
# ...
# PEM text (a certificate and its private key) that is held in memory.
# Here it is loaded into a StringBuilder from a file.
sbPem = chilkat.CkStringBuilder()
success = sbPem.LoadFile("c:/my_pem_files/a.pem","utf-8")
# ...
# Load the PEM text into a Pem object. The 2nd argument of LoadPem is the password of the
# private key. (Pass an empty string if the private key is not encrypted.)
pemPassword = "secret1"
pem = chilkat.CkPem()
success = pem.LoadPem(sbPem.getAsString(),pemPassword)
if (success == False):
print(pem.lastErrorText())
sys.exit()
success = crypt.AddPemSource(pem)
if (success == False):
print(crypt.lastErrorText())
sys.exit()
# Add as many PEM sources as desired...
# Each call to AddPemSource adds more certificates to the ones already added.
success = sbPem.LoadFile("c:/my_pem_files/b.pem","utf-8")
pemPassword = "secret2"
pem2 = chilkat.CkPem()
success = pem2.LoadPem(sbPem.getAsString(),pemPassword)
if (success == False):
print(pem2.lastErrorText())
sys.exit()
success = crypt.AddPemSource(pem2)
if (success == False):
print(crypt.lastErrorText())
sys.exit()
# ...
# ...