private void Call_Empty_Store_Window(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = FileDialog.CreateDefaultDialog(true); if (openFileDialog.ShowDialog() == true) { store_path = openFileDialog.FileName; EmptyStoreWindow emptyStoreWindow = new EmptyStoreWindow(); if (emptyStoreWindow.ShowDialog() == true) { Crypter crypter = new Crypter(emptyStoreWindow.Password.Password); byte[] encrypted = crypter.Encrypt(""); byte[] salty = UsefulTools.ComputeSaltySHA256(Encoding.UTF8.GetBytes(""), crypter.Salt); CryptoFile cryptoFile = new CryptoFile(encrypted, salty, crypter.IV, crypter.Salt); CryptoProtocol.Save(cryptoFile, store_path); Window window = new MainWindow(emptyStoreWindow.Password, new List <ServiceLoginPassword>(), store_path); window.Show(); this.Close(); return; } } }
private void Enter_Password(object sender, RoutedEventArgs e) { string password = Password1.Password; Password = new NetworkCredential("", Password1.Password); try { Crypter crypter = new Crypter(password, cryptoFile.Salt, cryptoFile.IV); string decrypt_data = crypter.Decrypt(cryptoFile.Cipher_text); byte[] hash = UsefulTools.ComputeSaltySHA256(Encoding.UTF8.GetBytes(decrypt_data), crypter.Salt); if (!StructuralComparisons.StructuralEqualityComparer.Equals(hash, cryptoFile.Hash)) { throw new CryptographicException(); } FillList(decrypt_data); this.DialogResult = true; } catch (CryptographicException exp) { string wront_password = (string)Application.Current.FindResource("wrong_password_string"); MessageBox.Show(wront_password, wront_password, MessageBoxButton.OK, MessageBoxImage.Error); } }