Exemple #1
0
 public static void RestoreDirectoryName(string folderPath)
 {
     try
     {
         NullChecks.Strings(folderPath);
         string anonymisedDirectoryName = Path.GetFileName(folderPath);
         // Get the path where the original directory name is stored
         string storageFileName = $"{anonymisedDirectoryName}.txt";
         string storageFilePath = Path.Combine(folderPath, storageFileName);
         if (File.Exists(storageFilePath))
         {
             string originalDirectoryName = File.ReadAllText(storageFilePath);
             string originalDirectoryPath = folderPath.Replace(anonymisedDirectoryName, originalDirectoryName);
             Directory.Move(folderPath, originalDirectoryPath);
             storageFilePath = Path.Combine(originalDirectoryPath, storageFileName);
             if (File.Exists(storageFilePath))
             {
                 File.Delete(storageFilePath);
             }
         }
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(folderPath, ex.GetType().Name, "Unable to restore original directory name.");
     }
 }
Exemple #2
0
 public static void SetAutoClearClipboard(ComboBox cmbAutoClearClipboard)
 {
     NullChecks.ComboBoxes(cmbAutoClearClipboard);
     if (Globals.ClearClipboardInterval == 15000)
     {
         cmbAutoClearClipboard.SelectedIndex = 1;
     }
     else if (Globals.ClearClipboardInterval == 30000)
     {
         cmbAutoClearClipboard.SelectedIndex = 2;
     }
     else if (Globals.ClearClipboardInterval == 60000)
     {
         cmbAutoClearClipboard.SelectedIndex = 3;
     }
     else if (Globals.ClearClipboardInterval == 90000)
     {
         cmbAutoClearClipboard.SelectedIndex = 4;
     }
     else if (Globals.ClearClipboardInterval == 120000)
     {
         cmbAutoClearClipboard.SelectedIndex = 5;
     }
     else
     {
         Globals.ClearClipboardInterval      = 1;
         cmbAutoClearClipboard.SelectedIndex = 0;
     }
 }
Exemple #3
0
 public static char[] ConvertUserInput(bool encryption, char[] base64Key, char[] password)
 {
     try
     {
         NullChecks.CharArray(base64Key);
         NullChecks.CharArray(password);
         char[] message;
         byte[] key = Convert.FromBase64CharArray(base64Key, 0, base64Key.Length);
         if (encryption == true)
         {
             byte[] plaintext = Encoding.UTF8.GetBytes(password);
             message = EncryptPassword(plaintext, key);
             Utilities.ZeroArray(plaintext);
         }
         else
         {
             byte[] ciphertext = Convert.FromBase64CharArray(password, 0, password.Length);
             message = DecryptPassword(ciphertext, key);
             Utilities.ZeroArray(ciphertext);
         }
         Utilities.ZeroArray(key);
         return(message);
     }
     catch (Exception ex) when(ex is FormatException || ex is EncoderFallbackException)
     {
         DisplayMessage.ErrorMessageBox(ex.GetType().Name, "Invalid key or password format.");
         return(Array.Empty <char>());
     }
 }
 public static void WriteHeaders(FileStream ciphertext, byte[] salt)
 {
     NullChecks.FileHeaders(ciphertext, salt);
     byte[] memorySizeFlag = Encoding.UTF8.GetBytes(Constants.MemorySizeFlag + Invariant.ToString(Globals.MemorySize));
     byte[] iterationsFlag = Encoding.UTF8.GetBytes(Constants.IterationsFlag + Invariant.ToString(Globals.Iterations));
     byte[] endFlag        = Encoding.UTF8.GetBytes(Constants.EndFlag);
     ciphertext.Write(memorySizeFlag, 0, memorySizeFlag.Length);
     ciphertext.Write(iterationsFlag, 0, iterationsFlag.Length);
     ciphertext.Write(endFlag, 0, endFlag.Length);
     ciphertext.Write(salt, 0, salt.Length);
 }
Exemple #5
0
 public static void SetOverwriteFiles(ComboBox cmbOverwriteFiles)
 {
     NullChecks.ComboBoxes(cmbOverwriteFiles);
     if (Globals.OverwriteFiles == true)
     {
         cmbOverwriteFiles.SelectedIndex = 0;
     }
     else
     {
         cmbOverwriteFiles.SelectedIndex = 1;
     }
 }
Exemple #6
0
 public static void SetAnonymousRename(ComboBox cmbAnonymousRename)
 {
     NullChecks.ComboBoxes(cmbAnonymousRename);
     if (Globals.AnonymousRename == true)
     {
         cmbAnonymousRename.SelectedIndex = 0;
     }
     else
     {
         cmbAnonymousRename.SelectedIndex = 1;
     }
 }
Exemple #7
0
 public static void SetMemoryEncryption(ComboBox cmbMemoryEncryption)
 {
     NullChecks.ComboBoxes(cmbMemoryEncryption);
     if (Globals.MemoryEncryption == true)
     {
         cmbMemoryEncryption.SelectedIndex = 0;
     }
     else
     {
         cmbMemoryEncryption.SelectedIndex = 1;
     }
 }
Exemple #8
0
 public static void SetTheme(ComboBox cmbTheme)
 {
     NullChecks.ComboBoxes(cmbTheme);
     if (Globals.DarkTheme == true)
     {
         cmbTheme.SelectedIndex = 0;
     }
     else
     {
         cmbTheme.SelectedIndex = 1;
     }
 }
Exemple #9
0
 public static void SetCheckForUpdates(ComboBox cmbCheckForUpdates)
 {
     NullChecks.ComboBoxes(cmbCheckForUpdates);
     if (Globals.CheckForUpdates == true)
     {
         cmbCheckForUpdates.SelectedIndex = 0;
     }
     else
     {
         cmbCheckForUpdates.SelectedIndex = 1;
     }
 }
Exemple #10
0
 public static void SetExitClearClipboard(ComboBox cmbExitClearClipboard)
 {
     NullChecks.ComboBoxes(cmbExitClearClipboard);
     if (Globals.ExitClearClipboard == true)
     {
         cmbExitClearClipboard.SelectedIndex = 0;
     }
     else
     {
         cmbExitClearClipboard.SelectedIndex = 1;
     }
 }
Exemple #11
0
 public static void SetAutoClearPassword(ComboBox cmbShredFilesMethod)
 {
     NullChecks.ComboBoxes(cmbShredFilesMethod);
     if (Globals.AutoClearPassword == true)
     {
         cmbShredFilesMethod.SelectedIndex = 0;
     }
     else
     {
         cmbShredFilesMethod.SelectedIndex = 1;
     }
 }
Exemple #12
0
 public static void SetShowPassword(ComboBox cmbShowPassword)
 {
     NullChecks.ComboBoxes(cmbShowPassword);
     if (Globals.ShowPasswordByDefault == true)
     {
         cmbShowPassword.SelectedIndex = 0;
     }
     else
     {
         cmbShowPassword.SelectedIndex = 1;
     }
 }
Exemple #13
0
 public static void SetIterations(NumericUpDown nudArgon2Iterations)
 {
     try
     {
         NullChecks.NumericUpDowns(nudArgon2Iterations);
         nudArgon2Iterations.Value = Globals.Iterations;
     }
     catch (ArgumentOutOfRangeException ex)
     {
         DisplayMessage.ErrorMessageBox(ex.GetType().Name, "Invalid 'Iterations' setting. The default setting will be used instead.");
         Globals.Iterations = Constants.DefaultIterations;
         Settings.SaveSettings();
         SetIterations(nudArgon2Iterations);
     }
 }
Exemple #14
0
 public static void SetMemorySize(NumericUpDown nudArgon2MemorySize)
 {
     try
     {
         NullChecks.NumericUpDowns(nudArgon2MemorySize);
         nudArgon2MemorySize.Value = Globals.MemorySize / Constants.Mebibyte;
     }
     catch (ArgumentOutOfRangeException ex)
     {
         DisplayMessage.ErrorMessageBox(ex.GetType().Name, "Invalid 'Memory Size' setting. The default setting will be used instead.");
         Globals.MemorySize = Constants.DefaultMemorySize;
         Settings.SaveSettings();
         SetMemorySize(nudArgon2MemorySize);
     }
 }
Exemple #15
0
 public static string GetAnonymousFileName(string filePath)
 {
     try
     {
         NullChecks.Strings(filePath);
         string originalFileName  = Path.GetFileName(filePath);
         string randomFileName    = GenerateRandomFileName();
         string anonymousFilePath = filePath.Replace(originalFileName, randomFileName);
         return(anonymousFilePath);
     }
     catch (ArgumentException ex)
     {
         Logging.LogException(ex.ToString(), Logging.Severity.Bug);
         DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "Unable to get anonymous file name. This is a bug - please report it.");
         return(filePath);
     }
 }
 public static bool AppendHash(string filePath, byte[] fileHash)
 {
     try
     {
         NullChecks.ByteArray(fileHash);
         using (var fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Read, Constants.FileBufferSize, FileOptions.RandomAccess))
         {
             fileStream.Write(fileHash, 0, fileHash.Length);
         }
         return(true);
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "Unable to append the MAC to the file. This data is required for decryption of the file.");
         return(false);
     }
 }
Exemple #17
0
 public static void BackgroundWorkerReportProgress(long progress, long total, BackgroundWorker backgroundWorker)
 {
     try
     {
         NullChecks.BackgroundWorkers(backgroundWorker);
         int percentage = (int)Math.Round((double)((double)progress / total) * 100);
         // Prevent unnecessary calls
         if (percentage != 0 && percentage != _previousPercentage)
         {
             backgroundWorker.ReportProgress(percentage);
         }
         _previousPercentage = percentage;
     }
     catch (Exception ex) when(ExceptionFilters.ReportProgressExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.Bug);
         DisplayMessage.ErrorResultsText(string.Empty, ex.GetType().Name, "Background worker report progress exception. This is a bug - please report it.");
     }
 }
Exemple #18
0
 public static void SetEncryptionAlgorithm(ComboBox cmbEncryptionAlgorithm)
 {
     NullChecks.ComboBoxes(cmbEncryptionAlgorithm);
     cmbEncryptionAlgorithm.SelectedIndex = 0;
 }