// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Text; using System.Security.Cryptography; namespace E { public class Program { public static void Main(string[] args) { byte[] cipher = new byte[10000]; Stream stm = new FileStream(@"C:\aes.dat", FileMode.Open, FileAccess.Read); int cipherlen = stm.Read(cipher, 0, cipher.Length); stm.Close(); string key = "Top hemmelig key"; byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; string data = "Top hemmelige data"; Rijndael aes = new RijndaelManaged(); aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; ICryptoTransform decrypt = aes.CreateDecryptor(Encoding.UTF8.GetBytes(key), iv); string newdata = Encoding.UTF8.GetString(decrypt.TransformFinalBlock(cipher, 0, cipherlen)); if(newdata != data) { Console.WriteLine("Oops"); } } } }