Exemple #1
0
        public void LockFile(string filepath, string password)
        {
            Validate PasswordValidate = new PasswordValidation(password);

            PasswordValidate.ValidateData();
            Validate FileExistsValidate = new SBNExists(Path.GetFileName(filepath));

            FileExistsValidate.ValidateData();
            CreateSTF GenerateSTF = new CreateSTF(filepath, HEADERCODE, ENDMARKER);

            GenerateSTF.GenerateSTF();

            IEncrypt Encrypter = new InstantiateElement().CreateNewInstance(ConfigurationSettings.AppSettings["Encrypter_Assembly"], Path.GetFileName(filepath), password) as IEncrypt;

            Encrypter.EncryptFile();
            string STFFilename = ConfigurationSettings.AppSettings["AllEntityLocation"] + Path.GetFileName(filepath) + "." + ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"];

            if (File.Exists(STFFilename))
            {
                File.Delete(STFFilename);
            }
            if (bool.Parse(ConfigurationSettings.AppSettings["DeleteSource"]) == true)
            {
                if (System.IO.File.Exists(filepath))
                {
                    System.IO.File.Delete(filepath);
                }
            }
        }
Exemple #2
0
        public void UnlockFolder(string Filename, string NewRoot, string Password)
        {
            #region Unlock Folder Implementation
            Validate PasswordValidate = new PasswordValidation(Password);
            PasswordValidate.ValidateData();
            string   SBNFilename = GetSBNName(Filename);
            string   STFFilename = GetSTFName(Filename);
            IDecrypt Decrypter   = new InstantiateElement().CreateNewInstance(ConfigurationSettings.AppSettings["Decrypter_Assembly"], Path.GetFileName(SBNFilename), Password) as IDecrypt;
            try
            {
                Decrypter.DecryptFile();
            }
            catch (Exception DecryptException)
            {
                throw (new ApplicationException("Incorrect password"));
            }

            ExtractSTF         ExtractSTFFile = new ExtractSTF(STFFilename);
            UnlockParameters   STFContents    = ExtractSTFFile.ExtractSTFContents();
            VerifySTFIntegrity CheckIntegrity = new VerifySTFIntegrity();
            if (!CheckIntegrity.Verify(STFContents.FooterCode))
            {
                throw (new ApplicationException("Incorrect password"));
            }
            DirectoryStructure CreateNewDirStructure = new DirectoryStructure(NewRoot, STFContents.XmlHeirarchy);
            CreateNewDirStructure.CreateDirectoryStructure();
            RestoreFiles RestoreFilesFromSTF = new RestoreFiles(STFContents.XmlHeirarchy, STFContents.FileAttributes, NewRoot, STFFilename);
            RestoreFilesFromSTF.ExecuteRestore();
            if (System.IO.File.Exists(STFFilename))
            {
                System.IO.File.Delete(STFFilename);
            }
            if (System.IO.File.Exists(ConfigurationSettings.AppSettings["AllEntityLocation"] + SBNFilename))
            {
                System.IO.File.Delete(ConfigurationSettings.AppSettings["AllEntityLocation"] + SBNFilename);
            }
            if (System.IO.File.Exists("GeneratedHierarchy.xml"))
            {
                System.IO.File.Delete("GeneratedHierarchy.xml");
            }



            #endregion
        }
Exemple #3
0
        public void LockFolder(string absoluteFolderPath, string Password)
        {
            #region LockFolder implementation
            LockParameters.FlushAll();
            Validate PasswordValidate = new PasswordValidation(Password);
            PasswordValidate.ValidateData();
            string   DirectoryName        = GetLeafDirectoryName(absoluteFolderPath);
            Validate FolderExistsValidate = new SBNExists(Path.GetFileName(DirectoryName));
            FolderExistsValidate.ValidateData();
            CreateFolderHierarchy createFolderHierarchy = new CreateFolderHierarchy(absoluteFolderPath);
            Root   fileSystemHierarchyManager           = createFolderHierarchy.FolderHierarchy;
            string DirName = Path.GetFileName(absoluteFolderPath);
            ConfigurationManager SaveConfiguration = new ConfigurationManager();
            SaveConfiguration.WriteFileHierarchyXml("HierarchySize.xml", fileSystemHierarchyManager);
            System.IO.FileInfo finfo = new FileInfo("HierarchySize.xml");
            long SizeOfXmlBlock      = finfo.Length;
            try
            {
                CreateSTF STF = new CreateSTF(SECURITYCODE, SizeOfXmlBlock, DirName, ENDMARKER, fileSystemHierarchyManager);
            }
            catch (Exception ex)
            {
                throw (new ApplicationException(ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"] + " File Creation Failed"));
            }
            IEncrypt Encrypter = new InstantiateElement().CreateNewInstance(ConfigurationSettings.AppSettings["Encrypter_Assembly"], DirName, Password) as IEncrypt;
            Encrypter.EncryptFile();
            System.IO.File.Delete(ConfigurationSettings.AppSettings["AllEntityLocation"] + DirName + "." + ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"]);
            if (bool.Parse(ConfigurationSettings.AppSettings["DeleteSource"]) == true)
            {
                if (System.IO.Directory.Exists(absoluteFolderPath))
                {
                    System.IO.Directory.Delete(absoluteFolderPath, true);
                }
            }

            if (System.IO.File.Exists("HierarchySize.xml"))
            {
                System.IO.File.Delete("HierarchySize.xml");
            }



            #endregion
        }
Exemple #4
0
        public void UnlockFile(string filename, string destination, string password)
        {
            Validate PasswordValidate = new PasswordValidation(password);

            PasswordValidate.ValidateData();
            IDecrypt Decrypter = new InstantiateElement().CreateNewInstance(ConfigurationSettings.AppSettings["Decrypter_Assembly"], GetSBNName(filename), password) as IDecrypt;

            try
            {
                Decrypter.DecryptFile();
            }
            catch (Exception DecryptFailure)
            {
                throw (new ApplicationException("Incorrect password"));
            }
            ExtractSTF STFContents = new ExtractSTF();

            UnlockParameters FileUnlockParams = STFContents.ExtractContents(string.Format("{0}{1}.{2}", ConfigurationSettings.AppSettings["AllEntityLocation"], filename, ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"]));

            if (!Directory.Exists(destination))
            {
                throw (new ApplicationException("The destination directory does not exists"));
            }
            else
            {
                RestoreFile RestoreOriginalFile = new RestoreFile();
                RestoreOriginalFile.ExecuteRestore(FileUnlockParams, string.Format("{0}{1}.{2}", ConfigurationSettings.AppSettings["AllEntityLocation"], filename, ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"]), destination);
                if (File.Exists(string.Format("{0}{1}.{2}", ConfigurationSettings.AppSettings["AllEntityLocation"], filename, ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"])))
                {
                    File.Delete(string.Format("{0}{1}.{2}", ConfigurationSettings.AppSettings["AllEntityLocation"], filename, ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"]));
                }
                if (File.Exists(string.Format("{0}{1}.{2}", ConfigurationSettings.AppSettings["AllEntityLocation"], filename, ConfigurationSettings.AppSettings["SecureExtension"])))
                {
                    File.Delete(string.Format("{0}{1}.{2}", ConfigurationSettings.AppSettings["AllEntityLocation"], filename, ConfigurationSettings.AppSettings["SecureExtension"]));
                }
            }
        }