Sample code for 30+ languages & platforms
C++

Load Certificate from .cer and Private Key from .pem

See more Certificates Examples

Load a certificate from a .cer and its associated private key from a .pem.

Chilkat C++ Downloads

C++
#include <CkCert.h>
#include <CkStringBuilder.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkCert cert;
    success = cert.LoadFromFile("C:/certs_and_keys/Certificate.cer");
    if (success == false) {
        std::cout << cert.lastErrorText() << "\r\n";
        return;
    }

    CkStringBuilder sbPem;
    success = sbPem.LoadFile("C:/certs_and_keys/PrivateKey.pem","utf-8");
    if (success == false) {
        std::cout << "Failed to load private key PEM" << "\r\n";
        return;
    }

    success = cert.SetPrivateKeyPem(sbPem.getAsString());
    if (success == false) {
        std::cout << cert.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "The certificate and associated private key are now loaded and ready for signing." << "\r\n";
    }