Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oCert
LOCAL oPrivKey

nSuccess := 0

//  The LoadFromFile method will automatically detect the file format..
oCert := CreateObject("Chilkat.Cert")
nSuccess := oCert:LoadFromFile("qa_data/zatca/cert.pem")
IF (nSuccess != 1)
    ? oCert:LastErrorText
    oCert:destroy()
    RETURN
ENDIF

? oCert:SubjectCN

//  Load the private key.
oPrivKey := CreateObject("Chilkat.PrivateKey")
nSuccess := oPrivKey:LoadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem")
IF (nSuccess != 1)
    ? oPrivKey:LastErrorText
    oCert:destroy()
    oPrivKey:destroy()
    RETURN
ENDIF

? "Key Type: " + oPrivKey:KeyType

//  Associate the private key with the certificate.
nSuccess := oCert:SetPrivateKey(oPrivKey)
IF (nSuccess != 1)
    ? oCert:LastErrorText
    oCert:destroy()
    oPrivKey:destroy()
    RETURN
ENDIF

? "Success."

oCert:destroy()
oPrivKey:destroy()