private void SendKey() { string msg = RSAProcessor.RSAEncrypt(publicKey, keyCreateRandom) + "<KEY><EOF>"; byte[] msgBytes = UTF32Encoding.Default.GetBytes(msg); clientCommunicateSocket.BeginSend(msgBytes, 0, msgBytes.Length, SocketFlags.None, null, null); ListBoxClientShow(string.Format("发送:{0}", keyCreateRandom)); }
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}", m_RijndaelCrypt.DencryptString(msg.Substring(0, msg.Length - 5), key))); } messageFromClient.Clear(); } }
private void RSAKeyInit() { RSAProcessor.CreateRSAKey(ref publicKey, ref pfxKey); }