Visual C++ Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Email Object
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

 

 

Create PKCS7 Signature using .cer and .key Files

Uses a digital certificate (.cer file) and private key file to create a PKCS7 signature.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
FreeBSD C++ Libraries
HP-UX C++ Libraries
BlackBerry QNX C++ Libraries
#include <CkCert.h>
#include <CkPrivateKey.h>
#include <CkCrypt2.h>
#include <CkByteData.h>

void ChilkatSample(void)
    {
    //  First, load the .cer and .key files into Chilkat objects...
    CkCert cert;

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

    CkPrivateKey privKey;
    const char * password;
    password = "myPassword";
    //  The private key object provides different methods for
    //  loading keys of many different formats.
    //  This example loads a PKCS8 encrypted private key.
    success = privKey.LoadPkcs8EncryptedFile("myPrivateKey.key",password);
    if (success != true) {
        printf("%s\n",privKey.lastErrorText());
        return;
    }

    //  NOTE:  In this example, the .cer should contain the public key
    //  that corresponds to the private key.

    CkCrypt2 crypt;

    //  Any string argument automatically begins the 30-day trial.
    success = crypt.UnlockComponent("30-day trial");
    if (success != true) {
        printf("%s\n",crypt.lastErrorText());
        return;
    }

    //  Set the certifcate + private key to be used for signing:
    crypt.SetSigningCert2(cert,privKey);

    CkByteData pkcs7;

    const char * textToSign;
    textToSign = "This is the text to be signed.";
    success = crypt.SignString(textToSign,pkcs7);
    if (success == false) {
        printf("%s\n",crypt.lastErrorText());
        return;
    }

    //  Save the PKCS7 signature to a file.
    success = pkcs7.saveFile("out_pkcs7.p7s");
    if (success == false) {
        printf("Failed to save output file.\n");
    }
    else {
        printf("Success.\n");
    }

    }

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

Mail Component · .NET Mail Component · XML Parser