예제 #1
0
        public static void Decrypt(string path, string key, CancellationToken cancelToken, Delegate DelegatePause)
        {
            try
            {
                if (cancelToken.IsCancellationRequested == false)
                {
                    bool wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
                    while (wait == true)
                    {
                        wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
                    }
                    InProgress = true;
                    Decryption(path, key, DelegatePause);
                    InProgress = false;
                }

                if (cancelToken.IsCancellationRequested == false)
                {
                    bool wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
                    while (wait == true)
                    {
                        wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
                    }
                    InProgress = true;
                    FileDirectoryOperations.DeleteDirectory(path);
                    InProgress = false;
                }

                if (cancelToken.IsCancellationRequested == false)
                {
                    bool wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
                    while (wait == true)
                    {
                        wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
                    }
                    InProgress = true;
                    string BackUpForDecription = getDestinationPath() + @"\BackEnd\BackupForDecription\";
                    FileDirectoryOperations.Replace(path, BackUpForDecription);
                    Console.WriteLine("Finish");
                    InProgress = false;
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
예제 #2
0
 public static void Encrypt(string path, string key, string BackupPathName, CancellationToken cancelToken, Delegate DelegatePause)
 {
     try
     {
         if (cancelToken.IsCancellationRequested == false)
         {
             bool wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             while (wait == true)
             {
                 wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             }
             InProgress = true;
             FileDirectoryOperations.CreateBackup(path, BackupPathName);
             InProgress = false;
         }
         if (cancelToken.IsCancellationRequested == false)
         {
             bool wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             while (wait == true)
             {
                 wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             }
             InProgress = true;
             Encryption(path, key, BackupPathName);
             InProgress = false;
         }
         string ExtraSymbolOnPath = "";
         if (cancelToken.IsCancellationRequested == false)
         {
             bool wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             while (wait == true)
             {
                 wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             }
             InProgress = true;
             string BackUpEncripted = getDestinationPath() + @"\BackEnd\BackupEncrypted";
             ExtraSymbolOnPath = FileDirectoryOperations.Replace(path, BackUpEncripted);
             InProgress        = false;
         }
         if (cancelToken.IsCancellationRequested == false)
         {
             bool wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             while (wait == true)
             {
                 wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             }
             InProgress = true;
             FileDirectoryOperations.MultiHashCalculator(path + ExtraSymbolOnPath + @"\");
             InProgress = false;
         }
         if (cancelToken.IsCancellationRequested == false)
         {
             bool wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             while (wait == true)
             {
                 wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
             }
             InProgress = true;
             string Backup = getDestinationPath() + @"\BackEnd\" + BackupPathName;
             FileDirectoryOperations.DeleteDirectory(Backup);
             Console.WriteLine("Finish");
             InProgress = false;
         }
     }
     catch (Exception exc)
     {
         Console.WriteLine(exc.Message);
     }
 }
예제 #3
0
        public static void Decryption(string path, string key, Delegate DelegatePause)
        {
            try
            {
                string projectDirectory    = getDestinationPath();
                string BackUpForDecription = projectDirectory + @"\BackEnd\BackupForDecription";
                Directory.CreateDirectory(BackUpForDecription);
                DirectoryInfo DirectInfo = new DirectoryInfo(path);

                List <string> HashesFromDB = Database.GetHashes();

                List <string> HashList = new List <string>();
                List <string> NameList = new List <string>();


                HashList = SplitStringList(HashesFromDB, ',', true);
                NameList = SplitStringList(HashesFromDB, ',', false);
                foreach (var fi in DirectInfo.EnumerateFiles())
                {
                    bool wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
                    if (wait == true)
                    {
                        while (wait == true)
                        {
                            wait = Convert.ToBoolean(DelegatePause.DynamicInvoke());
                        }
                    }
                    else
                    {
                        if (fi.Name.Contains(".zip") && fi.Name.Length == 18 + 4)
                        {
                            string SingleHash = FileDirectoryOperations.HashCalculator(fi.FullName);
                            if (HashList.Contains(SingleHash) && NameList.Contains(fi.Name))
                            {
                                string ZipFilePath = BackUpForDecription + "\\" + fi.Name;
                                AES.DecryptFile(@fi.FullName, BackUpForDecription + "\\" + fi.Name, key);
                                ZipFile.ExtractToDirectory(ZipFilePath, BackUpForDecription + "\\");
                                File.Delete(ZipFilePath);
                            }
                            else
                            {
                                File.Copy(fi.FullName, BackUpForDecription + "\\" + fi.Name);
                            }
                        }
                        else
                        {
                            string SingleHash = FileDirectoryOperations.HashCalculator(fi.FullName);
                            if (HashList.Contains(SingleHash) && NameList.Contains(fi.Name))
                            {
                                string outputFile = BackUpForDecription + "\\" + fi.Name;
                                AES.DecryptFile(fi.FullName, outputFile, key);
                            }
                            else
                            {
                                File.Copy(fi.FullName, BackUpForDecription + "\\" + fi.Name);
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }