Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C Examples

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


 

 

 

 

 

 

 

 

AES Encryption to Match PHP's Mcrypt Extension

Demonstrates how to match AES encryption results with PHP's mcrypt extension.

Please refer to this discussion about PHP AES Encryption. The code here matches the PHP mcrypt results on that page.

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_CkCrypt2.h>

void ChilkatSample(void)
    {
    HCkCrypt2 crypt;
    BOOL success;
    const char * ivAscii;
    const char * keyAscii;
    const char * plainText;
    const char * cipherText;

    crypt = CkCrypt2_Create();

    success = CkCrypt2_UnlockComponent(crypt,"Anything for 30-day trial");
    if (success != TRUE) {
        printf("Crypt component unlock failed\n");
        return;
    }

    //  AES is also known as Rijndael.
    CkCrypt2_putCryptAlgorithm(crypt,"aes");

    //  CipherMode may be "ecb" or "cbc"
    CkCrypt2_putCipherMode(crypt,"cbc");

    //  KeyLength may be 128, 192, 256
    CkCrypt2_putKeyLength(crypt,256);

    //  Pad with NULL bytes (PHP pads with NULL bytes)
    CkCrypt2_putPaddingScheme(crypt,3);

    //  EncodingMode specifies the encoding of the output for
    //  encryption, and the input for decryption.
    //  It may be "hex", "url", "base64", or "quoted-printable".
    CkCrypt2_putEncodingMode(crypt,"hex");

    ivAscii = "1234567890123456";
    CkCrypt2_SetEncodedIV(crypt,ivAscii,"ascii");

    //  The secret key must equal the size of the key.  For
    //  256-bit encryption, the binary secret key is 32 bytes.
    //  For 128-bit encryption, the binary secret key is 16 bytes.

    keyAscii = "12345678901234561234567890123456";
    CkCrypt2_SetEncodedKey(crypt,keyAscii,"ascii");

    plainText = "The quick brown fox jumped over the lazy dog";

    cipherText = CkCrypt2_encryptStringENC(crypt,plainText);
    printf("%s\n",cipherText);

    //  Do 128-bit AES encryption:
    CkCrypt2_putKeyLength(crypt,128);
    keyAscii = "1234567890123456";
    CkCrypt2_SetEncodedKey(crypt,keyAscii,"ascii");

    cipherText = CkCrypt2_encryptStringENC(crypt,plainText);
    printf("%s\n",cipherText);

    //  -------
    //  Results
    //  -------
    //  You may use these as test vectors for testing your AES implementations...
    // 
    //  ------------------------
    //  256-bit key, CBC mode
    //  ------------------------
    //  IV = '1234567890123456' 
    //   (hex: 31323334353637383930313233343536)
    //  Key = '12345678901234561234567890123456' 
    //   (hex: 3132333435363738393031323334353631323334353637383930313233343536)
    //  PlainText:
    //   'The quick brown fox jumped over the lazy dog'
	// CipherText(hex):
    //   2fddc3abec692e1572d9b7d629172a05caf230bc7c8fd2d26ccfd65f9c54526984f7cb1c4326ef058cd7bee3967299e3

    // 
    //  ------------------------
    //  128-bit key, CBC mode
    //  ------------------------
    //  IV = '1234567890123456' 
    //   (hex: 31323334353637383930313233343536)
    //  Key = '1234567890123456' 
    //   (hex: 31323334353637383930313233343536)
    //  PlainText:
    //   'The quick brown fox jumped over the lazy dog'
	// CipherText(hex):
    //   f78176ae8dfe84578529208d30f446bbb29a64dc388b5c0b63140a4f316b3f341fe7d3b1a3cc5113c81ef8dd714a1c99


    CkCrypt2_Dispose(crypt);

    }

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

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