Beispiel #1
0
        private void btnClientSend_Click(object sender, EventArgs e)
        {
            //加密消息体
            string msg = string.Format("{0}{1}", RijndaelProcessor.EncryptString(DateTime.Now.ToString(), keyCreateRandom), "<EOF>");

            byte[] msgBytes = UTF32Encoding.Default.GetBytes(msg);
            clientCommunicateSocket.BeginSend(msgBytes, 0, msgBytes.Length, SocketFlags.None, null, null);
            ListBoxClientShow(string.Format("发送:{0}", msg));
        }
Beispiel #2
0
 private void ProcessAndShowInClient()
 {
     //如果接收到<EOF>则表示完成一次接收,否则继续将自己置于接收状态
     if (messageFromServer.ToString().IndexOf("<EOF>") > -1)
     {
         //解密消息体并呈现出来
         ListBoxClientShow(string.Format("接收到服务器消息:{0}", RijndaelProcessor.DencryptString(messageFromServer.ToString().Substring(0, messageFromServer.ToString().Length - 5), keyCreateRandom)));
         messageFromServer.Clear();
     }
 }
Beispiel #3
0
        private void ProcessAndShowInServer()
        {
            string msg = messageFromClient.ToString();

            //如果接收到<EOF>则表示完成完成一次,否则继续将自己置于接收状态
            if (msg.IndexOf("<EOF>") > -1)
            {
                //如果客户端发送key,则负责初始化key
                if (msg.IndexOf("<KEY>") > -1)
                {
                    //用私钥解密发送过来的Key信息
                    key = RSAProcessor.RSADecrypt(pfxKey, msg.Substring(0, msg.Length - 10));
                    ListBoxServerShow(string.Format("接收到客户端密钥:{0}", key));
                }
                else
                {
                    //解密SSL通道中发送过来的密文并显式
                    ListBoxServerShow(string.Format("接收到客户端消息:{0}", RijndaelProcessor.DencryptString(msg.Substring(0, msg.Length - 5), key)));
                }
                messageFromClient.Clear();
            }
        }