Sample code for 30+ languages & platforms
Lianja

ZATCA Load Certificate and Private Key from PEM Files

See more ZATCA Examples

Demonstrates how to load a certificate and private key from a pair of PEM files.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

// The LoadFromFile method will automatically detect the file format..
loCert = createobject("CkCert")
llSuccess = loCert.LoadFromFile("qa_data/zatca/cert.pem")
if (llSuccess <> .T.) then
    ? loCert.LastErrorText
    release loCert
    return
endif

? loCert.SubjectCN

// Load the private key.
loPrivKey = createobject("CkPrivateKey")
llSuccess = loPrivKey.LoadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem")
if (llSuccess <> .T.) then
    ? loPrivKey.LastErrorText
    release loCert
    release loPrivKey
    return
endif

? "Key Type: " + loPrivKey.KeyType

// Associate the private key with the certificate.
llSuccess = loCert.SetPrivateKey(loPrivKey)
if (llSuccess <> .T.) then
    ? loCert.LastErrorText
    release loCert
    release loPrivKey
    return
endif

? "Success."


release loCert
release loPrivKey