Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C 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

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