Пример #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
 public static void PseudorandomData(string filePath, BackgroundWorker bgwShredFiles)
 {
     try
     {
         using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
         {
             byte[] randomBytes = FileHandling.GetBufferSize(fileStream);
             while (fileStream.Position < fileStream.Length)
             {
                 randomBytes = SodiumCore.GetRandomBytes(randomBytes.Length);
                 fileStream.Write(randomBytes, 0, randomBytes.Length);
                 ReportProgress.ReportEncryptionProgress(fileStream.Position, fileStream.Length, bgwShredFiles);
             }
         }
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "'1 Pass' erasure failed.");
     }
 }
Пример #3
0
 public static void ZeroFill(string filePath, bool useOnes, BackgroundWorker bgwShredFiles)
 {
     try
     {
         using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
         {
             byte[] zeroes = FileHandling.GetBufferSize(fileStream);
             if (useOnes == true)
             {
                 zeroes = FillArrayWithOnes(zeroes);
             }
             while (fileStream.Position < fileStream.Length)
             {
                 fileStream.Write(zeroes, 0, zeroes.Length);
                 ReportProgress.ReportEncryptionProgress(fileStream.Position, fileStream.Length, bgwShredFiles);
             }
         }
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "'Zero fill' erasure failed.");
     }
 }