This is a very simple example of encrypting a single 8-byte block of plaintext using the DES encryption algorithm (56-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 DES encryption implementation, which is available in .NET, ActiveX, Perl, Ruby, Python, Java (for Windows), and C++ libs.
// 56-bit DES encrypt a single 8-byte block (ECB mode)
// plain-text should be 8-bytes, key should be 8 bytes.
public byte[] DesEncryptOneBlock(byte[] plainText, byte[] key)
{
// Create a new DES key.
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
// Set the KeySize = 64 for 56-bit DES encryption.
// The msb of each byte is a parity bit, so the key length is actually 56 bits.
des.KeySize = 64;
des.Key = key;
des.Mode = CipherMode.ECB;
des.Padding = PaddingMode.None;
ICryptoTransform ic = des.CreateEncryptor();
byte[] enc = ic.TransformFinalBlock(plainText, 0,8);
return enc;
}