//++++++++++++++++++++++++++++
        //        Reading
        //++++++++++++++++++++++++++++

        public static Vault ReadFromConfig(VaultPaths paths, byte[] key)
        {
            var result = new Vault(paths.Name, key)
            {
                VaultPath = paths.FullVaultFolderPath
            };

            using var vaultFile = new FileStream(paths.VaultFilePath, FileMode.Open, FileAccess.Read);

            result.Header = VaultHeaderReader.ReadFrom(vaultFile);

            var(keyWasCorrect, password) = result.Header.MasterPassword.GetDecryptedPassword(key);

            if (!keyWasCorrect)
            {
                throw new CryptographicException(Strings.VaultReaderWriter_ReadFromConfig_Password_wasn_t_able_to_be_verified);
            }

            while (vaultFile.Position < vaultFile.Length)
            {
                result.UserDataFiles.Add(new UserDataFile(UserDataHeaderReader.ReadFrom(vaultFile, password)));
            }

            result.CheckAndCorrectAllItemHeaders();
            // TODO: check if cipher files exists, if not remove that file

            return(result);
        }
예제 #2
0
 public static Vault Open(VaultPaths folderPath, byte[] key)
 {
     return(VaultReaderWriter.ReadFromConfig(folderPath, key));
 }