Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (AesManaged aesManaged = new AesManaged())
- {
- //Console.WriteLine("Decrypting file using " + aesManaged.Mode + ", block size " + aesManaged.BlockSize + " and padding mode " + aesManaged.Padding + "...");
- byte[] salt = GetSaltFromCiphertext(cipherText);
- byte[] initializationVector = GetInitializationVectorFromCiphertext(cipherText);
- byte[] fileContentToDecrypt = GetContentFromCiphertext(cipherText);
- //Initialize the AES instance with the key and the initialization vector
- aesManaged.Key = GenerateKey(password, salt);
- aesManaged.IV = initializationVector;
- using (FileStream fileStream = new FileStream("../../Files/" + fileNameAndExtension, FileMode.Create))
- {
- using (CryptoStream cryptoStream = new CryptoStream(fileStream, aesManaged.CreateDecryptor(), CryptoStreamMode.Write))
- {
- cryptoStream.Write(fileContentToDecrypt, 0, fileContentToDecrypt.Length);
- }
- }
- }
Add Comment
Please, Sign In to add comment