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

 

 

 

 

 

 

 

 

AES Encrypt a Byte Array

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

This sample program demonstrates how to AES encrypt a byte array.

// The Chilkat Encryption library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.

// AES Encrypt a byte array.
void CryptExample(void)
    {
    CkCrypt2 crypt;
    
    // Any string passed to UnlockComponent automatically begins the 30-day trial.
    crypt.UnlockComponent("30-day trial");

    // Use AES encryption.
    crypt.put_CryptAlgorithm("aes");
    
    // Use 128-bit AES encryption.
    // It is also possible to use 192-bit or 256-bit AES encryption.
    crypt.put_KeyLength(128);

    // Create a binary secret key from a password string.
    CkByteData secretKey;
    crypt.GenerateSecretKey("myPassword",secretKey);
    crypt.put_SecretKey(secretKey);

    // Note: we could just as well set the binary secret key directly.
    // We need a binary key of 16 bytes (16 bytes * 8 bits/byte = 128 bits)
    // Example:
    // int i;
    // unsigned char sKey[16];
    // for (i=0; i<16; i++) sKey[i] = i;
    // secretKey.append(sKey,16);

    // Create some data to encrypt.
    int i;
    unsigned char data[100];
    for (i=0; i<100; i++) data[i] = i;

    // Encrypt a byte array:
    CkByteData inData;
    CkByteData encryptedData;
    // Borrow the data so an extra memory copy is not needed.
    inData.borrowData(data,100);
    crypt.EncryptBytes(inData,encryptedData);

    // Decrypt the byte array.
    CkByteData decryptedData;
    crypt.DecryptBytes(encryptedData,decryptedData);

    // Print the encrypted and decrypted data.
    CkString strTemp;
    strTemp.appendHexData(encryptedData.getData(),encryptedData.getSize());
    printf("%s\n",strTemp.getString());

    strTemp.clear();
    strTemp.appendHexData(decryptedData.getData(),decryptedData.getSize());
    printf("%s\n",strTemp.getString());

    // Prints:
    // NOTE: AES encryption pads the encrypted output to a multiple of 16 bytes.
    // D814 158C AF6B A38F AE29 672B B4E9 68FD 
    // EB53 C5D6 FA96 8F43 60BE F85A AAA8 6CA1 
    // 5E16 6956 6094 12D6 F61A A647 D4DB 698A 
    // E20F 4DCA 3FBA 5680 8E98 44C2 A08D B191 
    // 243E DDDA 0669 0D20 4B33 F4E7 EA82 7B63 
    // A798 D18D 8B54 4BAC 8E8C 340E FDFE 2452 
    // 0818 0554 9B62 A3DA 2222 81A1 FF52 B776 

    // 0001 0203 0405 0607 0809 0A0B 0C0D 0E0F 
    // 1011 1213 1415 1617 1819 1A1B 1C1D 1E1F 
    // 2021 2223 2425 2627 2829 2A2B 2C2D 2E2F 
    // 3031 3233 3435 3637 3839 3A3B 3C3D 3E3F 
    // 4041 4243 4445 4647 4849 4A4B 4C4D 4E4F 
    // 5051 5253 5455 5657 5859 5A5B 5C5D 5E5F 
    // 6061 6263 

 

 

 

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