private void SendKey() { keyCreateRandom = string.IsNullOrEmpty(txtPassword.Text) ? keyCreateRandom : txtPassword.Text; string msg = RASProcesser.RSAEncrypt(txtPublicKey.Text, keyCreateRandom) + "<KEY><EOF>"; byte[] msgBytes = EncodingInstance.Instance.GetBytes(msg); clientCommunicateSocket.BeginSend(msgBytes, 0, msgBytes.Length, SocketFlags.None, null, null); LogInfo(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 = RASProcesser.RSADecrypt(pfxKey, msg.Substring(0, msg.Length - 10)); LogInfo(string.Format("接收到客户端密钥:{0}", key)); } else { //解密SSL通道发送过来的密文并显示 LogInfo(string.Format("接收到客户端消息:{0}", RijndaelProcessor.DecryptString(msg.Substring(0, msg.Length - 5), key))); } messageFromClient.Clear(); } }
private void RSAKeyInit() { RASProcesser.CreateRSAKey(ref publicKey, ref pfxKey); txtPublicKey.Text = publicKey; }