Esempio n. 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();
        }
        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);
            }
        }
Esempio n. 3
0
        private void AlphaFS_File_ExportImportEncryptedFileRaw(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                // Create an encrypted file to use for testing
                var inputFile = System.IO.Path.Combine(tempRoot.Directory.FullName, "test.txt");
                System.IO.File.WriteAllText(inputFile, "Test file #1");

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


                // 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.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(tempRoot.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);
            }

            Console.WriteLine();
        }