Sample code for 30+ languages & platforms
C++

Import a Certificate (.cer file) into a Windows Certificate Store

See more Certificates Examples

Demonstrates how to import a certificate (without private key) into a Windows certificate store.

Chilkat C++ Downloads

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

void ChilkatSample(void)
    {
    bool success = false;

    CkCert cert;

    success = cert.LoadFromFile("qa_data/certs/example.cer");
    if (success == false) {
        std::cout << cert.lastErrorText() << "\r\n";
        return;
    }

    CkCertStore certStoreCU;
    bool readOnlyFlag = false;

    //  "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
    success = certStoreCU.OpenWindowsStore("CurrentUser","My",readOnlyFlag);
    if (success == false) {
        std::cout << "Failed to open the CurrentUser/My certificate store for read/write." << "\r\n";
        return;
    }

    //  Import the certificate into the CurrentUser/My certificate store.
    success = certStoreCU.AddCertificate(cert);
    if (success == false) {
        std::cout << certStoreCU.lastErrorText() << "\r\n";
        return;
    }

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