Unicode C
Unicode C
DKIM Signature using Windows Current User Certificate Store
See more DKIM / DomainKey Examples
This is a Windows-specific example to load a certificate from the Current User (registry-based) certificate store, and then use the certificate's associated private key for a DKIM signature.Chilkat Unicode C Downloads
#include <C_CkCertW.h>
#include <C_CkPrivateKeyW.h>
#include <C_CkDkimW.h>
void ChilkatSample(void)
{
BOOL success;
HCkCertW cert;
HCkPrivateKeyW privKey;
HCkDkimW dkim;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
cert = CkCertW_Create();
// The LoadByCommonName method searches the Windows Local Machine and Current User
// registry-based certificate stores for a certificate having the common name specified.
// If found, the certificate is loaded and ready for use.
success = CkCertW_LoadByCommonName(cert,L"My Certificate ABC");
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkCertW_Dispose(cert);
return;
}
// The certificate must have an associated private key installed, and it must be a
// private key that has been marked "exportable" when it was originally installed.
if (!CkCertW_HasPrivateKey(cert)) {
wprintf(L"This certificate does not have a private key available.\n");
CkCertW_Dispose(cert);
return;
}
privKey = CkPrivateKeyW_Create();
success = CkCertW_GetPrivateKey(cert,privKey);
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
return;
}
dkim = CkDkimW_Create();
// Load the private key into the DKIM object:
success = CkDkimW_SetDkimPrivateKey(dkim,privKey);
if (success == FALSE) {
wprintf(L"%s\n",CkDkimW_lastErrorText(dkim));
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
CkDkimW_Dispose(dkim);
return;
}
// The private key has been loaded into the DKIM object. See the other DKIM
// examples for guidance on how to create a DKIM signature...
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
CkDkimW_Dispose(dkim);
}