C
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
#include <C_CkCert.h>
#include <C_CkCertStore.h>
void ChilkatSample(void)
{
BOOL success;
HCkCert cert;
HCkCertStore certStoreCU;
BOOL readOnlyFlag;
success = FALSE;
cert = CkCert_Create();
success = CkCert_LoadFromFile(cert,"qa_data/certs/example.cer");
if (success == FALSE) {
printf("%s\n",CkCert_lastErrorText(cert));
CkCert_Dispose(cert);
return;
}
certStoreCU = CkCertStore_Create();
readOnlyFlag = FALSE;
// "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
success = CkCertStore_OpenWindowsStore(certStoreCU,"CurrentUser","My",readOnlyFlag);
if (success == FALSE) {
printf("Failed to open the CurrentUser/My certificate store for read/write.\n");
CkCert_Dispose(cert);
CkCertStore_Dispose(certStoreCU);
return;
}
// Import the certificate into the CurrentUser/My certificate store.
success = CkCertStore_AddCertificate(certStoreCU,cert);
if (success == FALSE) {
printf("%s\n",CkCertStore_lastErrorText(certStoreCU));
CkCert_Dispose(cert);
CkCertStore_Dispose(certStoreCU);
return;
}
printf("Imported %s\n",CkCert_subjectCN(cert));
printf("Success.\n");
CkCert_Dispose(cert);
CkCertStore_Dispose(certStoreCU);
}