(Perl) Import a Certificate (.cer file) into a Windows Certificate Store
Demonstrates how to import a certificate (without private key) into a Windows certificate store.
use chilkat();
$cert = chilkat::CkCert->new();
$success = $cert->LoadFromFile("qa_data/certs/example.cer");
if ($success == 0) {
print $cert->lastErrorText() . "\r\n";
exit;
}
$certStoreCU = chilkat::CkCertStore->new();
$readOnlyFlag = 0;
# "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
$success = $certStoreCU->OpenWindowsStore("CurrentUser","My",$readOnlyFlag);
if ($success == 0) {
print "Failed to open the CurrentUser/My certificate store for read/write." . "\r\n";
exit;
}
# Import the certificate into the CurrentUser/My certificate store.
$success = $certStoreCU->AddCertificate($cert);
if ($success == 0) {
print $certStoreCU->lastErrorText() . "\r\n";
exit;
}
print "Imported " . $cert->subjectCN() . "\r\n";
print "Success." . "\r\n";
|