예제 #1
0
        public override async Task Run()
        {
            VaultPaths paths;

            if (VaultPath == null)
            {
                paths = new VaultPaths(Environment.CurrentDirectory);
            }
            else
            {
                paths = new VaultPaths(VaultPath);
            }

            var key = PasswordPrompt.PromptPasswordAsHash();

            using var vault = Vault.Open(paths, key);

            if (File.Exists(ToAddPath))
            {
                await vault.AddFileAsync(ToAddPath);

                Notifier.Success(string.Format(Strings.AddCommandAsync_Run_Added_file__0__to_vault, ToAddPath));
            }
            else if (Directory.Exists(ToAddPath))
            {
                var progress = new Progress <ProgressReport>();
                progress.ProgressChanged += ProgressBar.PrintProgressBar;

                await AddDirectory(vault, progress);
            }
        }
예제 #2
0
        public static Vault Generate(string?vaultPath)
        {
            var key = PasswordPrompt.PromptPasswordAsHash();

            var paths = new VaultPaths(vaultPath);

            return(Vault.Open(paths, key));
        }
예제 #3
0
        public async Task VaultItemHeadersFileWriteRead()
        {
            const string vaultName = "TestVault";
            const string testFile  = Preparations.TestDataPath + "data.dat";
            var          key       = "passphrase".ApplySHA256();

            using var file = Vault.Create(vaultName, key, Preparations.TestFolderPath);
            await file.AddFileAsync(testFile);

            VaultReaderWriter.WriteConfig(file, key);

            var paths    = new VaultPaths($"{Preparations.TestFolderPath}/{vaultName}/");
            var readFile = VaultReaderWriter.ReadFromConfig(paths, key);
            await readFile.AddFileAsync(testFile, "others");

            var unused = VaultReaderWriter.ReadFromConfig(paths, key);
        }
예제 #4
0
        public async Task DecryptingFile()
        {
            const string vaultName    = "DFile";
            const string testFile     = Preparations.TestDataPath + "DecryptingFile.dat";
            var          unlockedPath = $"{Preparations.TestFolderPath}{vaultName}/Unlocked/DecryptingFile.dat";
            var          key          = CryptoRNG.GetRandomBytes(AesSizes.Key);

            var originalHash = GetFileHash(testFile);

            // create an encrypted file
            {
                using var vault = Vault.Create(vaultName, key, Preparations.TestFolderPath);
                await vault.AddFileAsync(testFile);
            }

            // decrypt the file
            {
                var paths = new VaultPaths($"{Preparations.TestFolderPath}{vaultName}/");
                using var vault = VaultReaderWriter.ReadFromConfig(paths, key);
                var status = await vault.ExtractFile(vault.UserDataFiles.First());

                Assert.AreEqual(ExtractStatus.Ok, status);

                Assert.IsTrue(vault.UserDataFiles.First().Header.IsUnlocked);

                await vault.EliminateExtracted(vault.UserDataFiles.First());

                Assert.IsFalse(vault.UserDataFiles.First().Header.IsUnlocked);

                await vault.ExtractFile(vault.UserDataFiles.First());

                Assert.IsTrue(vault.UserDataFiles.First().Header.IsUnlocked);
            }

            var decryptedHash = GetFileHash(unlockedPath);

            Assert.AreEqual(originalHash, decryptedHash);
        }