// 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.Text; using System.Security.Cryptography; class MainClass { public static void Main(string[] args) { Encoding utf = new UTF8Encoding(); Rijndael aes = new RijndaelManaged(); byte[] key = utf.GetBytes("hemmeligabcdefgh12345678"); byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; ICryptoTransform encrypt = aes.CreateEncryptor(key, iv); String plain1 = "Dette er en lille test"; byte[] cipher = encrypt.TransformFinalBlock(utf.GetBytes(plain1), 0, utf.GetByteCount(plain1)); for(int i = 0; i < cipher.Length; i++) { Console.WriteLine(cipher[i]); } ICryptoTransform decrypt = aes.CreateDecryptor(key, iv); String plain2 = utf.GetString(decrypt.TransformFinalBlock(cipher, 0, cipher.Length)); Console.WriteLine(plain2); } }