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

 

 

 

 

 

 

 

 

Matching .NET Framework AES Encryption Results

AES string encryption in C++ and the equivalent C# code using the .NET Framework.

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

void ChilkatSample(void)
    {

    //  First, here's the C# code we're trying to match:

    //  RijndaelManaged rman = new RijndaelManaged();
    //  rman.Mode = CipherMode.CBC;
    //  rman.Padding = PaddingMode.PKCS7;
    //  rman.KeySize = 256;

    //  Use a 32-byte key (for 256-bit encryption)
    //  byte [] keyBytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
    //  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };

    //  The IV for AES is 16 bytes, because the AES block size is 16.
    //  byte [] ivBytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

    //  ICryptoTransform encryptor = rman.CreateEncryptor(keyBytes, ivBytes);

    //  byte [] plainText = System.Text.Encoding.UTF8.GetBytes("This is a test");

    //  byte [] encrypted = encryptor.TransformFinalBlock(plainText, 0, plainText.Length);

    //  Output is 31k+86baFy9GJKQ9Y1ebCw==
    //  textBox1.Text = Convert.ToBase64String(encrypted);

    //  The following Chilkat code produces the same output:
    CkCrypt2 crypt;

    bool success;
    success = crypt.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        printf("Crypt component unlock failed\n");
        return;
    }

    crypt.put_CryptAlgorithm("aes");
    crypt.put_CipherMode("cbc");
    crypt.put_KeyLength(256);
    crypt.put_PaddingScheme(0);
    crypt.put_EncodingMode("base64");

    CkString ivHex;
    ivHex = "000102030405060708090A0B0C0D0E0F";
    CkString keyHex;
    keyHex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F";
    crypt.SetEncodedIV(ivHex,"hex");
    crypt.SetEncodedKey(keyHex,"hex");

    printf("%s\n",crypt.EncryptStringENC("This is a test"));


    }

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