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 Create(SecureString masterPassword) { using (var masterKey = AesKey.Generate()) { using (var derivedKey = await Argon2Key.Calculate(masterPassword)) { var encryptedMasterKey = await _aesCrypter.Encrypt(masterKey.Key, derivedKey.Value, masterKey.Iv); var storableModel = new StorageModel(encryptedMasterKey, (byte[])masterKey.Iv.Clone(), new List <PasswordModel>()); await _fileStorage.Store(storableModel); _masterKey = new byte[masterKey.Key.Length]; masterKey.Key.CopyTo(_masterKey, 0); ProtectedMemory.Protect(_masterKey, MemoryProtectionScope.SameProcess); } } }