예제 #1
0
파일: Chat_Form.cs 프로젝트: hohmd/Ragnarok
        //public byte[] AES_Key = new byte[32];
        //public byte[] AES_IV = new byte[16];


        public Chat_Form(Login_Form tf1)
        {
            InitializeComponent();
            f1 = tf1;
            TargetID_Lable.Text = "正在与 " + CFG.TargetID + " 聊天:";
            RSA_module.RSA_pair(out pubkey, out privkey);
            Thread Sh = new Thread(new ThreadStart(ShakeHand));

            Sh.Start();
            Sh.Join();
            Thread ChT = new Thread(new ThreadStart(OpenChat_tunnel));

            ChT.Start();
        }
예제 #2
0
        public Chat_Form()
        {
            InitializeComponent();
            TargetID_Lable.Text = "正在与 " + CFG.TargetID + " 聊天:";
            RSA_module.RSA_pair(out pubkey, out privkey);
            if (PUB.ActiveC)
            {
                PUB.s.Send(Encoding.UTF8.GetBytes(pubkey));

                tmp         = PUB.s.Receive(bytesReceived, bytesReceived.Length, 0);
                pubkey4send = Encoding.UTF8.GetString(bytesReceived, 0, tmp);

                AES_module.AES_Initialize(out AES_Key, out AES_IV);
                byte[] AES_Complex = AES_join(AES_Key, AES_IV);
                byte[] cipherkey   = RSA_module.RSAEncrypt(AES_Complex, pubkey4send);
                PUB.s.Send(cipherkey);
            }
            else
            {
                tmp         = PUB.s.Receive(bytesReceived, bytesReceived.Length, 0);
                pubkey4send = Encoding.UTF8.GetString(bytesReceived, 0, tmp);

                PUB.s.Send(Encoding.UTF8.GetBytes(pubkey));

                tmp = PUB.s.Receive(bytesReceived, bytesReceived.Length, 0);
                byte[] cipherkey = new byte[tmp];
                Array.Copy(bytesReceived, 0, cipherkey, 0, tmp);

                byte[] AES_Complex = RSA_module.RSADecrypt(cipherkey, privkey);
                Buffer.BlockCopy(AES_Complex, 0, AES_Key, 0, 32);
                Buffer.BlockCopy(AES_Complex, 32, AES_IV, 0, 16);
            }

            Thread Rx = new Thread(new ThreadStart(Recv));

            Rx.Start();
            SendMSG_Button.Enabled = true;
        }