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 Receive()
        {
            NetworkStream networkStream = new NetworkStream(this.ClientSocket);

            while (true)
            {
                Postman postMan = Postman.GetPackage(networkStream);
                Console.WriteLine(postMan);
                switch (postMan.Type)
                {
                case Postman.PostmanType.SEND_KEY:
                    this.ServerMysterio.PubKey = Mysterio.ConvertBytesToKey(postMan.Payload);
                    break;

                case Postman.PostmanType.SEND_MESSAGE:
                    string plainText = Mysterio.Decrypt(this.ClientMysterio.PriKey, postMan.Payload);
                    Console.WriteLine(plainText);
                    break;
                }
                if (postMan.Type == Postman.PostmanType.DISCONNECT)
                {
                    break;
                }
            }
            networkStream.Close();
        }
Beispiel #3
0
        private void Receive()
        {
            try
            {
                NetworkStream netStream = new NetworkStream(this.ReceiveSocket);
                while (true)
                {
                    Postman postman = Postman.GetPackage(netStream);
                    RenderForm();
                    switch (postman.Type)
                    {
                    case Postman.PostmanType.SEND_KEY:
                        this.OtherMysterio.PubKey = Mysterio.ConvertBytesToKey(postman.Payload);
                        break;

                    case Postman.PostmanType.SEND_MESSAGE:
                        string plainText = Mysterio.Decrypt(this.MyMysterio.PriKey, postman.Payload);
                        ThreadHelper.AppendMessages(this, txtMessages, DateTime.Now.ToString("MM/dd/yyyy h:mm:ss tt\t") + plainText, false);
                        break;
                    }
                    AddEvent(postman.Type.ToString(), Encoding.Unicode.GetString(postman.Payload));
                }
            }catch (Exception e)
            {
                //MessageBox.Show(e.Message);
                Stop();
            }
        }