C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

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


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

256-bit AES Encrypt to a Hex String

Download: Chilkat .NET Assemblies

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
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following the instructions at
http://www.example-code.com/vbdotnet/step2.asp

 

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