Visual C++ Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Visual C++ Examples

CkString
Byte Array
Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

 

Encrypt File to .p7m

C++ example program to encrypt a file to produce a .p7m as output. A digital certificate (public-key) is used for encrypting.

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

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

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

#include <CkCrypt2.h>
#include <CkCert.h>

void ChilkatSample(void)
    {

    CkCrypt2 crypt;

    //  Any string argument automatically begins the 30-day trial.
    bool success;
    success = crypt.UnlockComponent("30-day trial");
    if (success != true) {
        printf("Crypt component unlock failed\n");
        return;
    }

    //  Use public-key encryption with a digital certificate:
    crypt.put_CryptAlgorithm("pki");

    //  There are many ways to select and load a digital certificate.
    //  Certs can be retrieved from the Windows registry-based
    //  certificate stores, from database tables, files, etc.
    //  This example will load a .cer file.
    CkCert cert;

    success = cert.LoadFromFile("myCert.cer");
    if (success != true) {
        printf("%s\n",cert.lastErrorText());
        return;
    }

    crypt.SetEncryptCert(cert);

    //  The CkEncryptFile can encrypt files of any size.  The
    //  encryption occurs in streaming mode, so it is not necessary
    //  to hold the entire contents of the file in memory at once.
    success = crypt.CkEncryptFile("dude.gif","dude.p7m");
    if (success != true) {
        printf("%s\n",crypt.lastErrorText());
        return;
    }

    //  To decrypt the file, you'll need the private key.
    //  Also, the certificate should have already been installed
    //  on the computer.  This is typically achieved by installing
    //  from a .pfx file, or by importing from a certificate
    //  authority's online web application.  If you are decrypting
    //  from ASP, ASP.NET, or a Windows Service, you'll need to
    //  import in a way that provides the calling process permission
    //  to access and use the private key.  The procedure for
    //  doing this is explained here:
    //  http://blog.chilkatsoft.com/?p=149
    // 
    //  Also, there is no "SetDecryptCert" method.  The .p7m
    //  contains information that allows the Chilkat component
    //  to locate the certificate to be used for decryption.
    //  The Chilkat Crypt component automatically searches
    //  the Windows Current User certificate store and the
    //  Local Machine certificate store.
    success = crypt.CkDecryptFile("dude.p7m","dudeOut.gif");
    if (success != true) {
        printf("%s\n",crypt.lastErrorText());
        return;
    }


    }

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Mail Component · XML Parser