Пример #1
0
        private void AlphaFS_File_EncryptDecrypt_GetEncryptionStatus(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var file = tempRoot.CreateFile();

                Console.WriteLine("Input File Path: [{0}]", file.FullName);


                // Encrypt file.
                Alphaleonis.Win32.Filesystem.File.Encrypt(file.FullName);

                FileAssert.IsEncrypted(file.FullName);

                Assert.AreEqual(Alphaleonis.Win32.Filesystem.FileEncryptionStatus.Encrypted, Alphaleonis.Win32.Filesystem.File.GetEncryptionStatus(file.FullName), "The file is not encrypted, but it is expected.");


                // Decrypt file.
                Alphaleonis.Win32.Filesystem.File.Decrypt(file.FullName);

                FileAssert.IsNotEncrypted(file.FullName);

                Assert.AreNotEqual(Alphaleonis.Win32.Filesystem.FileEncryptionStatus.Encrypted, Alphaleonis.Win32.Filesystem.File.GetEncryptionStatus(file.FullName), "The file is encrypted, but it is not expected.");
            }

            Console.WriteLine();
        }
Пример #2
0
        private void AlphaFS_Directory_ExportImportEncryptedDirectoryRaw(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                // Create an encrypted file to use for testing.
                var inputDir = System.IO.Path.Combine(tempRoot.Directory.FullName, "testDir");
                System.IO.Directory.CreateDirectory(inputDir);
                System.IO.File.WriteAllText(System.IO.Path.Combine(inputDir, "test.txt"), "Test file");


                Alphaleonis.Win32.Filesystem.Directory.Encrypt(inputDir, false);


                Console.WriteLine("Encrypted Input Directory: [{0}]", inputDir);


                // Export the file using the method under test.
                var exportedFile = System.IO.Path.Combine(tempRoot.Directory.FullName, "export.dat");


                using (var fs = System.IO.File.Create(exportedFile))
                    Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw(inputDir, fs);


                Console.WriteLine("\nExported Input Directory: [{0}]", exportedFile);


                FileAssert.Exists(exportedFile);
                FileAssert.IsNotEncrypted(exportedFile);


                // Import the directory again.
                var importedDir = System.IO.Path.Combine(tempRoot.Directory.FullName, "importDir");


                using (var fs = System.IO.File.OpenRead(exportedFile))
                    Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw(fs, importedDir);


                Console.WriteLine("\nImported Input Directory: [{0}]", importedDir);


                // Verify that the imported file contents are equal to the original ones.
                DirectoryAssert.Exists(importedDir);
                DirectoryAssert.IsEncrypted(importedDir);
            }

            Console.WriteLine();
        }
        private void Directory_ExportImportEncryptedDirectoryRaw(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name))
            {
                // Create an encrypted file to use for testing.
                var inputDir = System.IO.Path.Combine(rootDir.Directory.FullName, "testDir");
                System.IO.Directory.CreateDirectory(inputDir);
                System.IO.File.WriteAllText(System.IO.Path.Combine(inputDir, "test.txt"), "Test file");

                Alphaleonis.Win32.Filesystem.Directory.Encrypt(inputDir, false);
                Console.WriteLine("\nEncrypted Input Directory: [{0}]", inputDir);


                // Export the file using the method under test.
                var exportedFile = System.IO.Path.Combine(rootDir.Directory.FullName, "export.dat");
                using (var fs = System.IO.File.Create(exportedFile))
                    Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw(inputDir, fs);
                Console.WriteLine("\nExported Input Directory: [{0}]", exportedFile);


                FileAssert.Exists(exportedFile);
                FileAssert.IsNotEncrypted(exportedFile);


                // Import the directory again.
                var importedDir = System.IO.Path.Combine(rootDir.Directory.FullName, "importDir");
                using (var fs = System.IO.File.OpenRead(exportedFile))
                    Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw(fs, importedDir);
                Console.WriteLine("\nImported Input Directory: [{0}]", importedDir);


                // Verify that the imported file contents are equal to the original ones.
                DirectoryAssert.Exists(importedDir);
                DirectoryAssert.IsEncrypted(importedDir);
            }

            Console.WriteLine();
        }
        private void File_ExportImportEncryptedFileRaw(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, "File.ExportImportEncryptedFileRaw"))
            {
                // Create an encrypted file to use for testing
                var inputFile = System.IO.Path.Combine(rootDir.Directory.FullName, "test.txt");
                System.IO.File.WriteAllText(inputFile, "Test file #1");

                Alphaleonis.Win32.Filesystem.File.Encrypt(inputFile);
                Console.WriteLine("\nEncrypted Input File: [{0}]", inputFile);


                // Export the file using the method under test.
                var exportedFile = System.IO.Path.Combine(rootDir.Directory.FullName, "export.dat");
                using (var fs = System.IO.File.Create(exportedFile))
                    Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw(inputFile, fs);
                Console.WriteLine("\nExported Input File: [{0}]", exportedFile);


                FileAssert.Exists(exportedFile);
                FileAssert.IsNotEncrypted(exportedFile);
                FileAssert.AreNotEqual(inputFile, exportedFile);


                // Import the file again.
                var importedFile = System.IO.Path.Combine(rootDir.Directory.FullName, "import.txt");
                using (var fs = System.IO.File.OpenRead(exportedFile))
                    Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw(fs, importedFile);
                Console.WriteLine("\nImported Input File: [{0}]", importedFile);


                // Verify that the imported file contents are equal to the original ones.
                FileAssert.Exists(importedFile);
                FileAssert.AreEqual(inputFile, importedFile);
                FileAssert.IsEncrypted(importedFile);
            }
        }