void clientReceiver() { TcpClient socket = this.client.socket; int reqLen = Helper.getBytes("msg").Length; byte[] req = new byte[reqLen]; NetworkStream netStream = socket.GetStream(); while (socket.Connected) { socket.Client.Receive(req); BinaryReader streamR = new BinaryReader(netStream); if (Helper.getString(req).Equals("msg")) { string sender = streamR.ReadString(); DialogResult result = MessageBox.Show( "Accept the Incoming File from " + sender, "Incoming Connection", MessageBoxButtons.YesNo ); if (result == DialogResult.Yes) { int dataLen = streamR.ReadInt32(); byte[] RecievedData = streamR.ReadBytes(dataLen); //SaveFileName = streamR.ReadString(); Message m = (Message)Helper.deSerilize(RecievedData); string sender_public_key = null; foreach (SomeData item in clientList) { if (item.username.Equals(sender)) { RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(CA); bool autinticated = rsa.VerifyHash( new SHA1Managed().ComputeHash(Helper.Serilize(item.info)), CryptoConfig.MapNameToOID("SHA1"), item.certificate ); if (autinticated) { sender_public_key = item.info.publicKey; } else { string msg = "not secure connection with " + sender + "\n do you want to complete process?"; if (MessageBox.Show(msg, "warning", MessageBoxButtons.YesNo) == DialogResult.Yes) { sender_public_key = item.info.publicKey; } else { return; } } break; } } if (AsymmetricEncryption.verifyMsg(sender_public_key, m)) { String res = AsymmetricEncryption.PGPDecrypt(m.msg, rsaProvider.ToXmlString(true)); client.saveFile(res, "D://" + info.username + "/" + m.file_name); FileStream stream = new FileStream("D://" + info.username + "/" + Path.GetFileNameWithoutExtension(m.file_name) + ".sign", FileMode.OpenOrCreate); stream.WriteByte(0); stream.Write(Helper.getBytes(sender_public_key), 0, sender_public_key.Length); stream.WriteByte(1); stream.Write(m.signature, 0, m.signature.Length); stream.Close(); } else { MessageBox.Show("not reliable message"); } } } else if (Helper.getString(req).Equals("lst")) { clientList.Clear(); int len = streamR.ReadInt32(); for (int i = 0; i < len; i++) { SomeData itm = new SomeData(); int l = streamR.ReadInt32(); itm = (SomeData)Helper.deSerilize(streamR.ReadBytes(l)); clientList.Add(itm); } this.Invoke((MethodInvoker)(() => ShowData())); } } }