// 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(); DES des = new DESCryptoServiceProvider(); byte[] key = utf.GetBytes("hemmelig"); byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 }; ICryptoTransform encrypt = des.CreateEncryptor(key, iv); string plain = "Dette er en lille test"; Console.WriteLine(plain); byte[] cipher = encrypt.TransformFinalBlock(utf.GetBytes(plain), 0, utf.GetByteCount(plain)); string cipherb64 = Convert.ToBase64String(cipher); Console.WriteLine(cipherb64); ICryptoTransform decrypt = des.CreateDecryptor(key, iv); byte[] cipher2 = Convert.FromBase64String(cipherb64); string plain2 = utf.GetString(decrypt.TransformFinalBlock(cipher2, 0, cipher.Length)); Console.WriteLine(plain2); } }