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"
// Needs #include <CkMime.h> // Needs #include <CkCertStore.h> // Needs #include <CkCert.h> // Needs #include <CkPrivateKey.h> CkString strOut; CkMime mime; bool success; success = mime.UnlockComponent("Anything for 30-day trial"); if (success == false) { strOut.append("Failed to unlock component\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } success = mime.LoadMimeFile("encryptedEmail.eml"); if (success != true) { strOut.append(mime.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } CkCertStore certStore; success = certStore.LoadPfxFile("myPfx.pfx","myPfxPassword"); if (success != true) { strOut.append(certStore.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Find the certificate by email address. There are many // ways to find certificates within a Chilkat certificate store // object... CkCert *cert = 0; cert = certStore.FindCertBySubjectE("support@chilkatsoft.com"); if (cert == 0 ) { strOut.append(certStore.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } CkPrivateKey *privKey = 0; privKey = cert->ExportPrivateKey(); if (privKey == 0 ) { strOut.append(cert->lastErrorText()); strOut.append("\r\n"); delete cert; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } success = mime.Decrypt2(*cert,*privKey); if (success != true) { strOut.append(mime.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Show the decrypted MIME: strOut.append(mime.GetMime()); strOut.append("\r\n"); delete cert; delete privKey; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.