Unicode C
Unicode C
Add S/MIME Signature using PFX
See more MIME Examples
Add a digital signature to a MIME message using the certificate + private key from a PFX file.Chilkat Unicode C Downloads
#include <C_CkMimeW.h>
#include <C_CkCertW.h>
void ChilkatSample(void)
{
BOOL success;
HCkMimeW mime;
HCkCertW cert;
const wchar_t *pfxFilepath;
const wchar_t *pfxPassword;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
mime = CkMimeW_Create();
// Load a PFX file into a certificate object.
cert = CkCertW_Create();
pfxFilepath = L"pfxFiles/something.pfx";
pfxPassword = L"secret";
success = CkCertW_LoadPfxFile(cert,pfxFilepath,pfxPassword);
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkMimeW_Dispose(mime);
CkCertW_Dispose(cert);
return;
}
success = CkMimeW_SetBodyFromPlainText(mime,L"This is the plain-text MIME body.");
CkMimeW_putCharset(mime,L"utf-8");
CkMimeW_putEncoding(mime,L"quoted-printable");
// Sign the MIME (adds a PKCS7 detached signature)
success = CkMimeW_AddDetachedSignature(mime,cert);
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
CkCertW_Dispose(cert);
return;
}
// Save the S/MIME to a file.
success = CkMimeW_SaveMime(mime,L"/temp/signedMime.txt");
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
CkCertW_Dispose(cert);
return;
}
wprintf(L"success!\n");
CkMimeW_Dispose(mime);
CkCertW_Dispose(cert);
}