Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
Decrypt MIME with PFXDemonstrates how to decrypt MIME using a PFX (containing a digital certificate with private key). The content-type of an encrypted MIME message looks like this: Content-Type: application/x-pkcs7-mime; name="smime.p7m"
#include <C_CkMime.h> #include <C_CkCertStore.h> #include <C_CkCert.h> #include <C_CkPrivateKey.h> void ChilkatSample(void) { HCkMime mime; BOOL success; HCkCertStore certStore; HCkCert cert; HCkPrivateKey privKey; mime = CkMime_Create(); success = CkMime_UnlockComponent(mime,"Anything for 30-day trial"); if (success == FALSE) { printf("Failed to unlock component\n"); return; } success = CkMime_LoadMimeFile(mime,"encryptedEmail.eml"); if (success != TRUE) { printf("%s\n",CkMime_lastErrorText(mime)); return; } certStore = CkCertStore_Create(); success = CkCertStore_LoadPfxFile(certStore,"myPfx.pfx","myPfxPassword"); if (success != TRUE) { printf("%s\n",CkCertStore_lastErrorText(certStore)); return; } // Find the certificate by email address. There are many // ways to find certificates within a Chilkat certificate store // object... cert = CkCertStore_FindCertBySubjectE(certStore,"support@chilkatsoft.com"); if (cert == 0 ) { printf("%s\n",CkCertStore_lastErrorText(certStore)); return; } privKey = CkCert_ExportPrivateKey(cert); if (privKey == 0 ) { printf("%s\n",CkCert_lastErrorText(cert)); CkCert_Dispose(cert); return; } success = CkMime_Decrypt2(mime,cert,privKey); if (success != TRUE) { printf("%s\n",CkMime_lastErrorText(mime)); return; } // Show the decrypted MIME: printf("%s\n",CkMime_getMime(mime)); CkCert_Dispose(cert); CkPrivateKey_Dispose(privKey); CkMime_Dispose(mime); CkCertStore_Dispose(certStore); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.