MFC Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

MFC Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
MIME
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip


 

 

 

 

 

 

 

 

Decrypt MIME with PFX

Demonstrates 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"

Download Chilkat C/C++ Libraries for VC++ 9.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64

Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE

Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible

// 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.