/// <summary> /// Set encrypted password (used if the master password is changed) /// </summary> /// <param name="encryptedPassword"></param> public void SetEncryptedPassword(string encryptedPassword) { _encryptedPassword = encryptedPassword; if (!_encrypted) { _passwordValue = AESEncryption.DecryptWithPassword(_encryptedPassword, _masterPassword); } }
/// <summary> /// Load binary encrypted data from a given file. /// </summary> /// <param name="path"></param> /// <param name="decryptionPassword"></param> /// <returns></returns> public List <CredentialEntry> OpenEncrypted(string path, SecureString decryptionPassword) { // create binary formatter BinaryFormatter formatter = new BinaryFormatter(); // Deserialize the file SaveData deserialized; byte[] encryptedBytes = File.ReadAllBytes(path); byte[] decryptionBytes = AESEncryption.DecryptWithPassword(encryptedBytes, decryptionPassword); if (decryptionBytes == null) { throw new Exception("Wrong Password."); } try { MemoryStream memoryStream = new MemoryStream(decryptionBytes, 0, decryptionBytes.Length); deserialized = (SaveData)formatter.Deserialize(memoryStream); } catch { throw new Exception("Unable to open file."); } List <CredentialEntry> collection = new List <CredentialEntry>(); // fill in loaded data foreach (SerializeableCredentialEntry deserializedEntry in deserialized.CredentialEntries) { CredentialEntry entry = new CredentialEntry(decryptionPassword, deserializedEntry.Password); entry.Title = deserializedEntry.Title; entry.Id = deserializedEntry.Id; entry.UserName = deserializedEntry.UserName; entry.ProvidedName = deserializedEntry.ProvidedName; entry.AddressData = deserializedEntry.AddressData; entry.Url = deserializedEntry.Url; entry.Email = deserializedEntry.Email; collection.Add(entry); } // Return the object return(collection); }