Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
256-bit AES Encrypt to a Hex String
C# example program to encrypt a string and return the binary encrypted data as a hex string. // Encrypt a string and return the encrypted data as a hexidecimalized string
// Uses 256-bit AES encryption.
Chilkat.Crypt2 crypt2 = new Chilkat.Crypt2();
crypt2.UnlockComponent("anything for 30-day trial");
crypt2.CryptAlgorithm = "aes";
crypt2.KeyLength = 256;
crypt2.EncodingMode = "hex";
// C# uses Unicode strings, but we want to encrypt 1 byte per char.
crypt2.Charset = "us-ascii";
// Generate a binary secret key according to the KeyLength.
// The SecretKey property is a byte array that can be set
// directly by passing a byte array equal in bit-length to
// the KeyLength, or you can let the Crypt2 component generate
// a binary secret key given a password string.
crypt2.SecretKey = crypt2.GenerateSecretKey("myPassword");
// C# passes the Unicode string to EncryptStringENC.
// Here is what happens internal to crypt2:
// 1) The Unicode string is converted according to the
// crypt2.Charset property. In this case, it converts
// to us-ascii (1-byte/char).
// 2) The data is 256-bit AES encrypted.
// 3) The resultant binary data is encoded to a string according
// to the EncodingMode (hex) and returned.
textBox1.Text = crypt2.EncryptStringENC("Encrypt This!");
// The output of this example is:
// 4D55BBE6DFA47582EA3BC95D1EA8BBD6
// An example of a C++ program that decrypts this data can
// be found here: C++ 256-bit AES Decrypt Hex String
Important: The download for this
example does not contain the ChilkatDotNet.dll which |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.