// 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.Net; using System.Net.Sockets; using System.Text; using System.Security.Cryptography; namespace E { public class Server { private static Encoding utf = new UTF8Encoding(); private static Rijndael aes = new RijndaelManaged(); private static byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; public static void Main(string[] args) { TcpListener srv = new TcpListener(IPAddress.Any, 1234); srv.Start(); TcpClient cli = srv.AcceptTcpClient(); Stream stm = new CryptoStream(cli.GetStream(), aes.CreateDecryptor(utf.GetBytes("hemmelig12345678"), iv), CryptoStreamMode.Read); int n = stm.ReadByte(); for(int i = 0; i < n; i++) { int v = stm.ReadByte(); if(v != i) { throw new Exception("Ooops"); } } stm.Close(); cli.Close(); srv.Stop(); Console.WriteLine(n + " bytes processed OK"); } } }