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 <CkCert.h>
#include <CkPrivateKey.h>

void ChilkatSample(void)
    {
    bool success = false;

    // The LoadFromFile method will automatically detect the file format..
    CkCert cert;
    success = cert.LoadFromFile("qa_data/zatca/cert.pem");
    if (success != true) {
        std::cout << cert.lastErrorText() << "\r\n";
        return;
    }

    std::cout << cert.subjectCN() << "\r\n";

    // Load the private key.
    CkPrivateKey privKey;
    success = privKey.LoadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem");
    if (success != true) {
        std::cout << privKey.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "Key Type: " << privKey.keyType() << "\r\n";

    // Associate the private key with the certificate.
    success = cert.SetPrivateKey(privKey);
    if (success != true) {
        std::cout << cert.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "Success." << "\r\n";
    }