public static void Main(string[] args)
        {
            Console.InputEncoding  = Encoding.Unicode;
            Console.OutputEncoding = Encoding.Unicode;

            Mysterio s = new Mysterio(2048);

            Mysterio c = new Mysterio(2048);

            byte[] sPri = Mysterio.ConvertKeyToBytes(s.PriKey);

            byte[] cPri = Mysterio.ConvertKeyToBytes(c.PriKey);

            string plain = "Gửi từ server";

            byte[] s_to_c = Mysterio.Encrypt(c.PubKey, plain);

            string in_c_result = Mysterio.Decrypt(c.PriKey, s_to_c);

            Console.WriteLine("in_c_result: " + in_c_result);

            plain = "gưởi từ client";

            byte[] c_to_s = Mysterio.Encrypt(s.PubKey, plain);

            string in_s_result = Mysterio.Decrypt(s.PriKey, c_to_s);

            Console.WriteLine("in_s_result: " + in_s_result);

            Console.ReadLine();
        }
        void Send()
        {
            NetworkStream networkStream = new NetworkStream(this.ClientSocket);

            while (true)
            {
                string  str     = Console.ReadLine();
                Postman postMan = new Postman();

                switch (str.ToUpper())
                {
                case "SEND_KEY":
                    postMan.Type    = Postman.PostmanType.SEND_KEY;
                    postMan.Payload = Mysterio.ConvertKeyToBytes(this.ClientMysterio.PubKey);
                    break;

                default:
                    postMan.Type    = Postman.PostmanType.SEND_MESSAGE;
                    postMan.Payload = Mysterio.Encrypt(this.ServerMysterio.PubKey, str);
                    break;
                }

                Postman.SendPackage(networkStream, postMan);
                if (str.ToUpper().Equals("QUIT"))
                {
                    break;
                }
            }

            networkStream.Close();
        }
Beispiel #3
0
        private void Send()
        {
            NetworkStream netStream = new NetworkStream(this.ReceiveSocket);
            Postman       postman   = new Postman()
            {
                Type    = Postman.PostmanType.SEND_KEY,
                Payload = Mysterio.ConvertKeyToBytes(this.MyMysterio.PubKey)
            };

            Postman.SendPackage(netStream, postman);
            AddEvent(postman.Type.ToString(), Encoding.Unicode.GetString(postman.Payload));
        }