Unicode C
Unicode C
PKCS7 Decrypt MIME
See more MIME Examples
Loads a PKCS7 encrypted MIME file and decrypts. The cert and private key used for decryption is loaded from a PFX file.Chilkat Unicode C Downloads
#include <C_CkMimeW.h>
void ChilkatSample(void)
{
BOOL success;
HCkMimeW mime;
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 the MIME
success = CkMimeW_LoadMimeFile(mime,L"encryptedMime.txt");
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
return;
}
// The AddPfxSourceFile and/or AddPfxSourceData
// methods may be called one or more times (one per PFX)
// to add sources from which the MIME component will
// search for certificates and private keys when decrypting.
pfxPassword = L"myPassword";
success = CkMimeW_AddPfxSourceFile(mime,L"myCertAndPrivateKey.pfx",pfxPassword);
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
return;
}
// Decrypt...
success = CkMimeW_Decrypt(mime);
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
return;
}
// Display the decrypted MIME:
wprintf(L"%s\n",CkMimeW_getMime(mime));
CkMimeW_Dispose(mime);
}