(Ruby) Import a Certificate (.cer file) into a Windows Certificate Store
Demonstrates how to import a certificate (without private key) into a Windows certificate store.
require 'chilkat'
cert = Chilkat::CkCert.new()
success = cert.LoadFromFile("qa_data/certs/example.cer")
if (success == false)
print cert.lastErrorText() + "\n";
exit
end
certStoreCU = Chilkat::CkCertStore.new()
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)
print "Failed to open the CurrentUser/My certificate store for read/write." + "\n";
exit
end
# Import the certificate into the CurrentUser/My certificate store.
success = certStoreCU.AddCertificate(cert)
if (success == false)
print certStoreCU.lastErrorText() + "\n";
exit
end
print "Imported " + cert.subjectCN() + "\n";
print "Success." + "\n";
|