(Unicode C++) Import a Certificate (.cer file) into a Windows Certificate Store
Demonstrates how to import a certificate (without private key) into a Windows certificate store.
#include <CkCertW.h>
#include <CkCertStoreW.h>
void ChilkatSample(void)
{
CkCertW cert;
bool success = cert.LoadFromFile(L"qa_data/certs/example.cer");
if (success == false) {
wprintf(L"%s\n",cert.lastErrorText());
return;
}
CkCertStoreW certStoreCU;
bool readOnlyFlag = false;
// "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
success = certStoreCU.OpenWindowsStore(L"CurrentUser",L"My",readOnlyFlag);
if (success == false) {
wprintf(L"Failed to open the CurrentUser/My certificate store for read/write.\n");
return;
}
// Import the certificate into the CurrentUser/My certificate store.
success = certStoreCU.AddCertificate(cert);
if (success == false) {
wprintf(L"%s\n",certStoreCU.lastErrorText());
return;
}
wprintf(L"Imported %s\n",cert.subjectCN());
wprintf(L"Success.\n");
}
|