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#
bool success = false;

Chilkat.Cert cert = new Chilkat.Cert();

success = cert.LoadFromFile("qa_data/certs/example.cer");
if (success == false) {
    Debug.WriteLine(cert.LastErrorText);
    return;
}

Chilkat.CertStore certStoreCU = new Chilkat.CertStore();
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) {
    Debug.WriteLine("Failed to open the CurrentUser/My certificate store for read/write.");
    return;
}

//  Import the certificate into the CurrentUser/My certificate store.
success = certStoreCU.AddCertificate(cert);
if (success == false) {
    Debug.WriteLine(certStoreCU.LastErrorText);
    return;
}

Debug.WriteLine("Imported " + cert.SubjectCN);
Debug.WriteLine("Success.");