// (c) 2006 Richard Grimes // www.grimes.demon.co.uk using System; using System.Security.Cryptography; using System.Net.Sockets; using System.Net; using System.Text; class Bob { static void Main() { TcpClient client = new TcpClient(); client.Connect(IPAddress.Loopback, 5000); NetworkStream stm = client.GetStream(); if (args.Length > 0) { byte[] quit = Encoding.ASCII.GetBytes(args[0]); stm.Write(quit, 0, quit.Length); client.Close(); return; } byte[] buf = Encoding.ASCII.GetBytes("KEY"); stm.Write(buf, 0, buf.Length); byte[] readBuf = new byte[client.ReceiveBufferSize]; int read = stm.Read(readBuf, 0, readBuf.Length); string reply = Encoding.ASCII.GetString(readBuf, 0, read); if (reply.ToLower() == "ack") { RandomNumberGenerator rand = RandomNumberGenerator.Create(); byte[] key = new byte[128]; rand.GetBytes(key); Console.WriteLine(BitConverter.ToString(key)); stm.Write(key, 0, key.Length); } client.Close(); } }