Sample code for 30+ languages & platforms
JavaScript

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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

var cert = new CkCert();

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

var certStoreCU = new CkCertStore();
var 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) {
    console.log("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) {
    console.log(certStoreCU.LastErrorText);
    return;
}

console.log("Imported " + cert.SubjectCN);
console.log("Success.");