This is a very simple example of encrypting a single 8-byte block of plaintext using the 3DES encryption algorithm (168-bit key, ECB mode). It does not use the Chilkat encryption component. The purpose of this example is to help in verifying the results of Chilkat’s 3DES encryption implementation, which is available in .NET, ActiveX, Perl, Ruby, Python, Java (for Windows), and C++ libs.
// 168-bit (three-key) 3DES (Triple-DES) encrypt a single 8-byte block (ECB mode)
// plain-text should be 8-bytes, key should be 24 bytes.
public byte[] TripleDesEncryptOneBlock(byte[] plainText, byte[] key)
{
// Create a new 3DES key.
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
// Set the KeySize = 192 for 168-bit DES encryption.
// The msb of each byte is a parity bit, so the key length is actually 168 bits.
des.KeySize = 192;
des.Key = key;
des.Mode = CipherMode.ECB;
des.Padding = PaddingMode.None;
ICryptoTransform ic = des.CreateEncryptor();
byte[] enc = ic.TransformFinalBlock(plainText, 0,8);
return enc;
}