Esempio n. 1
0
        public static void Decrypt(FileStream plaintext, FileStream ciphertext, byte[] fileBytes, byte[] nonce, byte[] key, BackgroundWorker bgwDecryption)
        {
            NullChecks.FileEncryption(plaintext, ciphertext, fileBytes, nonce, key);
            int bytesRead;

            while ((bytesRead = ciphertext.Read(fileBytes, 0, fileBytes.Length)) > 0)
            {
                byte[] decryptedBytes = DecryptFileBytes(fileBytes, nonce, key);
                plaintext.Write(decryptedBytes, 0, bytesRead);
                // Report progress if decrypting a single file
                ReportProgress.ReportEncryptionProgress(plaintext.Position, ciphertext.Length, bgwDecryption);
            }
        }
Esempio n. 2
0
 public static void DecryptAesCBC(FileStream plaintext, FileStream ciphertext, byte[] fileBytes, byte[] nonce, byte[] key, BackgroundWorker bgwDecryption)
 {
     NullChecks.FileEncryption(plaintext, ciphertext, fileBytes, nonce, key);
     using (var aes = new AesCryptoServiceProvider()
     {
         Mode = _cbcMode, Padding = _pkcs7Padding
     })
     {
         using (var cryptoStream = new CryptoStream(ciphertext, aes.CreateDecryptor(key, nonce), CryptoStreamMode.Read))
         {
             int bytesRead;
             while ((bytesRead = cryptoStream.Read(fileBytes, 0, fileBytes.Length)) > 0)
             {
                 plaintext.Write(fileBytes, 0, bytesRead);
                 // Report progress if encrypting a single file
                 ReportProgress.ReportEncryptionProgress(plaintext.Position, ciphertext.Length, bgwDecryption);
             }
         }
     }
 }