private void HandShakeRequestHandler(HandShakeRequest request) { EncryptionkeyObject encryptionkeyObject = new EncryptionkeyObject(); encryptionkeyObject.FirstX = BitConverter.ToDouble(UtilityFunction.DecryptByte(privateKey, request.FirstX), 0); encryptionkeyObject.U = BitConverter.ToDouble(UtilityFunction.DecryptByte(privateKey, request.U), 0); encryptionkeyObject.SelectChoas = (ChoasEnum)BitConverter.ToInt16(UtilityFunction.DecryptByte(privateKey, request.SelectChoas), 0); if (clientPublicEncryptionkeys.ContainsKey(request.SenderClient)) { clientPublicEncryptionkeys[request.SenderClient] = encryptionkeyObject; } else { clientPublicEncryptionkeys.Add(request.SenderClient, encryptionkeyObject); } }
private void SessionResponseHandler(SessionResponse response) { if (response.IsConfirmed) { if (clientPublicKey.ContainsKey(response.ClientName)) { clientPublicKey[response.ClientName] = response.PublicKey; } else { clientPublicKey.Add(response.ClientName, response.PublicKey); } HandShakeRequest handShakeRequest = new HandShakeRequest(); EncryptionkeyObject encryptionkeyObject = new EncryptionkeyObject(); Random rnd = new Random(); encryptionkeyObject.FirstX = rnd.NextDouble(); encryptionkeyObject.U = rnd.NextDouble(); encryptionkeyObject.SelectChoas = rnd.Next(0, 2) == 0 ? ChoasEnum.First : ChoasEnum.Secend; if (clientPublicEncryptionkeys.ContainsKey(response.ClientName)) { clientPublicEncryptionkeys[response.ClientName] = encryptionkeyObject; } else { clientPublicEncryptionkeys.Add(response.ClientName, encryptionkeyObject); } handShakeRequest.FirstX = UtilityFunction.EncryptByte(response.PublicKey, BitConverter.GetBytes(encryptionkeyObject.FirstX)); handShakeRequest.U = UtilityFunction.EncryptByte(response.PublicKey, BitConverter.GetBytes(encryptionkeyObject.U)); handShakeRequest.SelectChoas = UtilityFunction.EncryptByte(response.PublicKey, BitConverter.GetBytes((short)encryptionkeyObject.SelectChoas)); handShakeRequest.ReceiverClient = response.ClientName; SendMessage(handShakeRequest); } }