public async Task <IList <LazyPasswordEntry> > GetAll() { var data = await _fileStorage.Read(); using (var masterKey = await _masterKeyManager.Get()) { var passwords = new List <LazyPasswordEntry>(); foreach (var p in data.Passwords) { var decryptedName = await _aesCrypter.Decrypt(p.EncryptedUserName, masterKey.Value, p.Iv); var decryptedDescription = await _aesCrypter.Decrypt(p.EncryptedDescription, masterKey.Value, p.Iv); passwords.Add(new LazyPasswordEntry( p.Id, Encoding.ASCII.GetString(decryptedName), Encoding.ASCII.GetString(decryptedDescription), p.EncryptedPassword, p.Iv, _aesCrypter)); } return(passwords); } }
public async Task Load(SecureString masterPassword) { using (var derivedKey = await Argon2Key.Calculate(masterPassword)) { var data = await _fileStorage.Read(); var decryptedMasterKey = await _aesCrypter.Decrypt(data.EncryptedMasterKey, derivedKey.Value, data.Iv); _masterKey = decryptedMasterKey; ProtectedMemory.Protect(_masterKey, MemoryProtectionScope.SameProcess); } }
public async Task <SecureString> GetPassword(byte[] masterKey) { var decryptedPassword = await _aesCrypter.Decrypt(_encryptedPassword, masterKey, _iv); var securePassword = new SecureString(); var secureKeyCharArray = Encoding.ASCII.GetChars(decryptedPassword); for (int i = 0; i < secureKeyCharArray.Length; i++) { securePassword.AppendChar(secureKeyCharArray[i]); secureKeyCharArray[i] = (char)0; } securePassword.MakeReadOnly(); return(securePassword); }
async void doSomthingAsych() { try { FileStream data = (FileStream)openFileDialog1.OpenFile(); setProgress(2); Stream encrypted = aes.Decrypt(data); setProgress(4); FileStream s = (FileStream)saveFileDialog1.OpenFile(); setProgress(6); encrypted.CopyTo(s); encrypted.Close(); data.Close(); s.Close(); setProgress(10); } catch (Exception ex) { setColor(Color.Red); appedConsole($"Error: {ex.ToString()}\n"); } }