// (c) 2006 Richard Grimes // www.grimes.demon.co.uk using System; using System.Security.Cryptography; using System.Text; using System.IO; class App { static void Main() { Rijndael r = Rijndael.Create(); r.Mode = CipherMode.ECB; r.Padding = PaddingMode.None; string phrase = "daisy, daisy, give me your answer to"; PasswordDeriveBytes pdb = new PasswordDeriveBytes(phrase, new byte[0]); r.Key = pdb.GetBytes(r.KeySize >> 3); string data = "repeated.text...repeated.text...repeated.text...repeated.text..."; byte[] input = Encoding.ASCII.GetBytes(data); ICryptoTransform en = r.CreateEncryptor(); input = CryptoTransform(input, en); Console.WriteLine(BitConverter.ToString(input)); ICryptoTransform de = r.CreateDecryptor(); byte[] output = CryptoTransform(input, de); Console.WriteLine(Encoding.ASCII.GetString(output)); } static byte[] CryptoTransform(byte[] input, ICryptoTransform en) { MemoryStream sInput = new MemoryStream(input); CryptoStream cs = new CryptoStream(sInput, en, CryptoStreamMode.Read); MemoryStream sOutput = new MemoryStream(); byte[] buffer = new byte[1024]; while (true) { int read = cs.Read(buffer, 0, buffer.Length); if (read == 0) break; sOutput.Write(buffer, 0, read); } cs.Clear(); return sOutput.ToArray(); } }