예제 #1
0
        static void Main(string[] args)
        {
            int        port          = 13356;                       //My connection setup
            IPAddress  ip            = IPAddress.Parse("127.0.0.1");
            IPEndPoint localEndpoint = new IPEndPoint(ip, port);

            TcpListener listener = new TcpListener(localEndpoint);

            listener.Start();

            Console.WriteLine("Awaiting Clients");
            TcpClient client = listener.AcceptTcpClient();

            Console.WriteLine("Client Connected");
            NetworkStream stream  = client.GetStream();                //Connected
            Encryption    cryp    = new Encryption(keychat(stream));
            string        message = "";

            while (client.Connected)                                 //My loop for checking if it need to read a message or send one.
            {
                if (stream.DataAvailable)
                {
                    Console.WriteLine(cryp.AESdecrypted(ReadMessage(stream)));
                }
                else if (Console.KeyAvailable)                                      //Generate my message to send
                {
                    ConsoleKeyInfo keypressed = Console.ReadKey();
                    if (keypressed.Key == ConsoleKey.Enter && message.Length > 0)
                    {
                        SendMessage(stream, cryp.encrypt(message));
                        Console.WriteLine(message);
                        Console.WriteLine(cryp.encrypt(message));
                        message = "";
                    }
                    else if (keypressed.Key == ConsoleKey.Backspace)
                    {
                        if (message.Length > 0)
                        {
                            message = message.Remove(message.Length - 1, 1);
                        }
                    }
                    else
                    {
                        message += keypressed.KeyChar.ToString();
                    }                                                               //End of generating my message to send
                }
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: Gutzon/Sikkerhed
        static void Main(string[] args)
        {
            string      v      = "";
            Encryption  crypt  = new Encryption("keyeee");
            Encryption  crypt2 = new Encryption("keyeee");
            Keyexchange keye   = new Keyexchange();

            Console.WriteLine("Hello World!");
            while (true)
            {
                v = Console.ReadLine();
                string text = "";
                foreach (byte b in crypt.AESencrypted(v))
                {
                    text += b.ToString();
                }

                Console.WriteLine(crypt.AESencrypted(v));
                Console.WriteLine(crypt2.AESdecrypted(crypt.AESencrypted(v)));
                text = "";
                foreach (byte b in crypt.myAes.Key)
                {
                    text += b.ToString();
                }
                Console.WriteLine("cryp:  " + text);
                text = "";
                foreach (byte b in crypt2.myAes.Key)
                {
                    text += b.ToString();
                }
                Console.WriteLine("cryp2: " + text);
                text = "";
                foreach (byte b in crypt.myAes.IV)
                {
                    text += b.ToString();
                }
                Console.WriteLine("iv:  " + text);
                text = "";
                foreach (byte b in crypt2.myAes.IV)
                {
                    text += b.ToString();
                }
                Console.WriteLine("iv2: " + text);
                Console.WriteLine("iv2: " + text);
                Console.WriteLine(keye.generatekey(2).ToString());
            }
        }