// 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) { 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 encrypt = aes.CreateEncryptor(Encoding.UTF8.GetBytes(key), iv); byte[] cipher = encrypt.TransformFinalBlock(Encoding.UTF8.GetBytes(data), 0, Encoding.UTF8.GetByteCount(data)); Stream stm = new FileStream(@"C:\aes.dat", FileMode.Create, FileAccess.Write); stm.Write(cipher, 0, cipher.Length); stm.Close(); } } }