Guest User

Untitled

a guest
May 17th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using (AesManaged aesManaged = new AesManaged())
  2. {
  3. //Console.WriteLine("Decrypting file using " + aesManaged.Mode + ", block size " + aesManaged.BlockSize + " and padding mode " + aesManaged.Padding + "...");
  4.  
  5. byte[] salt = GetSaltFromCiphertext(cipherText);
  6. byte[] initializationVector = GetInitializationVectorFromCiphertext(cipherText);
  7. byte[] fileContentToDecrypt = GetContentFromCiphertext(cipherText);
  8.  
  9. //Initialize the AES instance with the key and the initialization vector
  10. aesManaged.Key = GenerateKey(password, salt);
  11. aesManaged.IV = initializationVector;
  12.  
  13. using (FileStream fileStream = new FileStream("../../Files/" + fileNameAndExtension, FileMode.Create))
  14. {
  15. using (CryptoStream cryptoStream = new CryptoStream(fileStream, aesManaged.CreateDecryptor(), CryptoStreamMode.Write))
  16. {
  17. cryptoStream.Write(fileContentToDecrypt, 0, fileContentToDecrypt.Length);
  18. }
  19. }
  20. }
Add Comment
Please, Sign In to add comment