Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

loCert = createobject("CkCert")
llSuccess = loCert.LoadFromFile("C:/certs_and_keys/Certificate.cer")
if (llSuccess = .F.) then
    ? loCert.LastErrorText
    release loCert
    return
endif

loSbPem = createobject("CkStringBuilder")
llSuccess = loSbPem.LoadFile("C:/certs_and_keys/PrivateKey.pem","utf-8")
if (llSuccess = .F.) then
    ? "Failed to load private key PEM"
    release loCert
    release loSbPem
    return
endif

llSuccess = loCert.SetPrivateKeyPem(loSbPem.GetAsString())
if (llSuccess = .F.) then
    ? loCert.LastErrorText
    release loCert
    release loSbPem
    return
endif

? "The certificate and associated private key are now loaded and ready for signing."


release loCert
release loSbPem