示例#1
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
        }
示例#2
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"]));
                }
            }
        }