private async void listen_btn_Click(object sender, RoutedEventArgs e) { listen_btn.Visibility = Visibility.Hidden; register_btn.Visibility = Visibility.Hidden; //SetVisibilityOfElements(new object[] {pb, stop_listen_btn, QrCodeImage}, Visibility.Visible); pb.Visibility = Visibility.Visible; stop_listen_btn.Visibility = Visibility.Visible; await bm.ReceiveConnection(); BluetoothClientWrapper bluetoothRemoteClient = bm.BluetoothRemoteClient; if (bluetoothRemoteClient != null) { bm.VerifyClient(); uint userSap = bluetoothRemoteClient.GetClient().RemoteEndPoint.Address.Sap; // Get the encrypted key from memory if the user exists. if (!File.Exists($"C:\\Users\\extre\\Desktop\\HostLocker\\user_{userSap}_data.dat")) { throw new Exception("User does not exist."); } UserData user = DataProtector.LoadData(userSap); UserDevice = new UserDevice(user); UserDevice.BluetoothConnection = bluetoothRemoteClient; string request = UserDevice.PrepareDecryptRequest(UserDevice.EncryptedSymmetricKey); bluetoothRemoteClient.SendMessage(request); string requestResponse = bluetoothRemoteClient.ReadFromBtDevice(); //Handle the response string decryptedMessage = UserDevice.DecodeAndDecryptMessage(requestResponse); JsonRemote decryptedObject = JsonConvert.DeserializeObject <JsonRemote>(decryptedMessage); UserDevice.aesManager.SetKey(JsonConvert.DeserializeObject <byte[]>(decryptedObject.DecipheredContent), user.UserAesInitVect); Switcher.Switch(new FilesWindow(), UserDevice); } pb.Visibility = Visibility.Hidden; listen_btn.Visibility = Visibility.Visible; register_btn.Visibility = Visibility.Visible; stop_listen_btn.Visibility = Visibility.Hidden; //bm.Dispose(true); }
private async void register_btn_Click(object sender, RoutedEventArgs e) { listen_btn.Visibility = Visibility.Hidden; register_btn.Visibility = Visibility.Hidden; //SetVisibilityOfElements(new object[] {pb, stop_listen_btn, QrCodeImage}, Visibility.Visible); pb.Visibility = Visibility.Visible; stop_listen_btn.Visibility = Visibility.Visible; QrCodeImage.Visibility = Visibility.Visible; UserDevice = new UserDevice(); QrCodeManager qrCodeManager = new QrCodeManager(UserDevice); QrCodeImage.Source = qrCodeManager.GenerateQrImage(); QrCodeImage.Visibility = Visibility.Visible; await bm.ReceiveConnection(); BluetoothClientWrapper bluetoothRemoteClient = bm.BluetoothRemoteClient; if (bluetoothRemoteClient != null) { bm.VerifyClient(); UserDevice.BluetoothConnection = bluetoothRemoteClient; string messageReceived = bluetoothRemoteClient.ReadFromBtDevice(); JsonRemote messageDecrypted = UserDevice.DecryptedObjReceived(messageReceived); UserDevice.DevicePublicKey = messageDecrypted.PublicKey.RSAParameters; Switcher.Switch(new FilesWindow(), UserDevice); } QrCodeImage.Source = null; //SetVisibilityOfElements(new object[] { pb, QrCodeImage }, Visibility.Hidden); pb.Visibility = Visibility.Hidden; QrCodeImage.Visibility = Visibility.Hidden; //bm.Dispose(true); //Console.WriteLine(bc.ReadFromBtDevice()); //bc.sendMessage("It wokrs||!!"); }