예제 #1
0
 public static void EncryptionErasure(string filePath, BackgroundWorker bgwShredFiles)
 {
     try
     {
         string encryptedFilePath = AnonymousRename.GetAnonymousFileName(filePath);
         using (var ciphertext = new FileStream(encryptedFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
             using (var plaintext = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
             {
                 byte[] fileBytes = FileHandling.GetBufferSize(plaintext);
                 byte[] key       = SodiumCore.GetRandomBytes(Constants.EncryptionKeySize);
                 byte[] nonce     = SodiumCore.GetRandomBytes(Constants.XChaChaNonceLength);
                 StreamCiphers.Encrypt(plaintext, ciphertext, 0, fileBytes, nonce, key, bgwShredFiles);
                 Utilities.ZeroArray(key);
                 Utilities.ZeroArray(nonce);
             }
         // Overwrite the original file
         File.Copy(encryptedFilePath, filePath, true);
         ShredFiles.EraseFileMetadata(encryptedFilePath);
         File.Delete(encryptedFilePath);
     }
     catch (Exception ex) when(ex is CryptographicException || ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "'Encryption' erasure failed.");
     }
 }
예제 #2
0
 private static void ShredDirectory(string directoryPath, ref int progress, BackgroundWorker bgwShredFiles)
 {
     try
     {
         var directoryInfo = new DirectoryInfo(directoryPath)
         {
             Attributes = FileAttributes.NotContentIndexed
         };
         string[] files = Directory.GetFiles(directoryPath, "*.*", SearchOption.AllDirectories);
         Globals.TotalCount += files.Length;
         foreach (string filePath in files)
         {
             CallShredFilesMethod(filePath, ref progress, bgwShredFiles);
         }
         string anonymisedDirectoryPath = AnonymousRename.MoveFile(directoryPath, false);
         Directory.Delete(anonymisedDirectoryPath, true);
         Globals.ResultsText     += $"{Path.GetFileName(directoryPath)}: Folder erasure successful.{Environment.NewLine}";
         Globals.SuccessfulCount += 1;
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(directoryPath, ex.GetType().Name, "Unable to access the directory.");
     }
 }
예제 #3
0
 private static string GetEncryptedFilePath(string filePath)
 {
     if (Globals.AnonymousRename == true)
     {
         bool success = OriginalFileName.AppendOriginalFileName(filePath);
         if (success == true)
         {
             return(AnonymousRename.GetAnonymousFileName(filePath) + Constants.EncryptedExtension);
         }
     }
     return(filePath + Constants.EncryptedExtension);
 }
예제 #4
0
 private static void DeleteFile(string filePath)
 {
     try
     {
         string anonymisedFilePath = AnonymousRename.MoveFile(filePath, true);
         EraseFileMetadata(anonymisedFilePath);
         File.Delete(anonymisedFilePath);
         Globals.ResultsText     += $"{Path.GetFileName(filePath)}: File erasure successful." + Environment.NewLine;
         Globals.SuccessfulCount += 1;
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "Unable to delete the file.");
     }
 }
예제 #5
0
 public static bool CreateKeyfile()
 {
     using (var saveFileDialog = new VistaSaveFileDialog())
     {
         saveFileDialog.Title        = "Create Keyfile";
         saveFileDialog.DefaultExt   = ".key";
         saveFileDialog.AddExtension = true;
         saveFileDialog.FileName     = AnonymousRename.GenerateRandomFileName();
         if (saveFileDialog.ShowDialog() == DialogResult.OK)
         {
             Globals.KeyfilePath = saveFileDialog.FileName;
             bool success = GenerateKeyfile(Globals.KeyfilePath);
             return(success);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #6
0
 private static void DirectoryEncryption(bool encryption, string folderPath, byte[] passwordBytes, ref int progress, BackgroundWorker backgroundWorker)
 {
     try
     {
         // Anonymise directory names before encryption (if enabled)
         folderPath = AnonymousRename.AnonymiseDirectories(encryption, folderPath);
         // Get all files in all directories
         string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
         // -1 for the selected directory
         Globals.TotalCount += files.Length - 1;
         foreach (string filePath in files)
         {
             CallEncryption(encryption, filePath, passwordBytes, ref progress, backgroundWorker);
         }
         // Deanonymise directory names after decryption (if enabled)
         AnonymousRename.DeanonymiseDirectories(encryption, folderPath);
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(folderPath, ex.GetType().Name, "Unable to get files in the directory.");
     }
 }