Unicode C++
Unicode C++
Decrypt a .p7m File (using a PFX)
See more Encryption Examples
_LANGUAGE_ sample code showing how to decrypt a .p7m using a .p12 / .pfx certificate w/ private key.Chilkat Unicode C++ Downloads
#include <CkCrypt2W.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkCrypt2W crypt;
// Use a digital certificate and private key from a PFX file (.pfx or .p12).
const wchar_t *pfxPath = L"myCertAndKey.pfx";
const wchar_t *pfxPassword = L"test123";
success = crypt.AddPfxSourceFile(pfxPath,pfxPassword);
if (success != true) {
wprintf(L"%s\n",crypt.lastErrorText());
return;
}
// Set the outPath to whatever is appropriate.
// If you are decrypting a PDF, your output might be "out.pdf"...
const wchar_t *inPath = L"smime.p7m";
const wchar_t *outPath = L"original.txt";
// Indicate that we're doing public key decryption (i.e. PKCS7)
crypt.put_CryptAlgorithm(L"pki");
success = crypt.CkDecryptFile(inPath,outPath);
if (success == false) {
wprintf(L"%s\n",crypt.lastErrorText());
return;
}
wprintf(L"Success.\n");
}