DES ExampleThe DES algorithm has been around for a long time, and the 56-bit version is now easily crackable (in less than a day on fairly modest equipment). The IV value used is "012345678". [Lecture] [Tutorial] [Paper] Encrypted (Base-64) Encrypted (Hex) Decrypted |
Presentation
Code Used
public void des(string message, string inkey) { if (message == null) return; if (inkey == null) return; try { TripleDES desobj = new DESCryptoServiceProvider(); desobj.Key = StringToByte(inkey, 8); // convert to 8 characters - 64 bits desobj.IV = StringToByte("12345678"); byte[] key = desobj.Key; byte[] IV = desobj.IV; ICryptoTransform encryptor = desobj.CreateEncryptor(key, IV); MemoryStream msEncrypt = new MemoryStream(); CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write); // Write all data to the crypto stream and flush it. csEncrypt.Write(StringToByte(message), 0, StringToByte(message).Length); csEncrypt.FlushFinalBlock(); // Get the encrypted array of bytes. byte[] encrypted1 = msEncrypt.ToArray(); encrypted = ByteToString(encrypted1); ICryptoTransform decryptor = desobj.CreateDecryptor(key, IV); // Now decrypt the previously encrypted message using the decryptor MemoryStream msDecrypt = new MemoryStream(encrypted1); CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read); decrypted = ByteToString(csDecrypt); } catch (Exception ex) { encrypted = "Error:" + ex.Message.ToString(); } }