Sample code for 30+ languages & platforms
C

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

C
#include <C_CkCert.h>
#include <C_CkPrivateKey.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkCert cert;
    HCkPrivateKey privKey;

    success = FALSE;

    // The LoadFromFile method will automatically detect the file format..
    cert = CkCert_Create();
    success = CkCert_LoadFromFile(cert,"qa_data/zatca/cert.pem");
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        CkCert_Dispose(cert);
        return;
    }

    printf("%s\n",CkCert_subjectCN(cert));

    // Load the private key.
    privKey = CkPrivateKey_Create();
    success = CkPrivateKey_LoadPemFile(privKey,"qa_data/zatca/ec-secp256k1-priv-key.pem");
    if (success != TRUE) {
        printf("%s\n",CkPrivateKey_lastErrorText(privKey));
        CkCert_Dispose(cert);
        CkPrivateKey_Dispose(privKey);
        return;
    }

    printf("Key Type: %s\n",CkPrivateKey_keyType(privKey));

    // Associate the private key with the certificate.
    success = CkCert_SetPrivateKey(cert,privKey);
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        CkCert_Dispose(cert);
        CkPrivateKey_Dispose(privKey);
        return;
    }

    printf("Success.\n");


    CkCert_Dispose(cert);
    CkPrivateKey_Dispose(privKey);

    }