Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loCert
LOCAL loPrivKey

lnSuccess = 0

* The LoadFromFile method will automatically detect the file format..
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCert.LoadFromFile("qa_data/zatca/cert.pem")
IF (lnSuccess <> 1) THEN
    ? loCert.LastErrorText
    RELEASE loCert
    CANCEL
ENDIF

? loCert.SubjectCN

* Load the private key.
loPrivKey = CreateObject('Chilkat.PrivateKey')
lnSuccess = loPrivKey.LoadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem")
IF (lnSuccess <> 1) THEN
    ? loPrivKey.LastErrorText
    RELEASE loCert
    RELEASE loPrivKey
    CANCEL
ENDIF

? "Key Type: " + loPrivKey.KeyType

* Associate the private key with the certificate.
lnSuccess = loCert.SetPrivateKey(loPrivKey)
IF (lnSuccess <> 1) THEN
    ? loCert.LastErrorText
    RELEASE loCert
    RELEASE loPrivKey
    CANCEL
ENDIF

? "Success."

RELEASE loCert
RELEASE loPrivKey