Esempio n. 1
0
        /// <summary>
        /// 接收到需要返回解密的处理方式
        /// </summary>
        private string ReciveNeedDecrypt(Socket socketSend)
        {
            RSAKey    rk       = new RSAKey();
            RSAChange rDecrypt = new RSAChange();

            ///接收
            byte[] buffer = new byte[1024 * 5];                    //一次为5k
            int    r      = socketSend.Receive(buffer);            //接收
            string str    = Encoding.UTF8.GetString(buffer, 0, r); //转成字符串

            ///解密
            string strDecrypt = rDecrypt.RSADecrypt(rk.getRSAKey(@"privateKey.xml"), str);//解密

            return(strDecrypt);
        }
Esempio n. 2
0
        /// <summary>
        /// 接收到需要返回公钥的处理方式
        /// </summary>
        private void ReciveNeedPublicKey(Socket socketSend)
        {
            RSAKey rk = new RSAKey();

            rk.setRSAKey(@"privateKey.xml", @"publicKey.xml");//创建公钥私钥,并写入指定文件夹内

            ///序号
            string type = "PK";

            byte[] num = Encoding.UTF8.GetBytes(type);

            ///公钥
            string sKey = rk.getRSAKey(@"publicKey.xml");

            byte[] keyBu = Encoding.UTF8.GetBytes(sKey);

            ///发送
            socketSend.Send(num, 2, 0);              //发送序号
            socketSend.Send(keyBu, keyBu.Length, 0); //发送公钥
        }