This is the code -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace AESFileDecrypt
{
class Program
{
static void Main(string[] args)
{
RijndaelManaged aes = new RijndaelManaged();
aes.Key = Encoding.ASCII.GetBytes("12345678");
aes.IV = new byte[0x10];
aes.Padding = PaddingMode.None;
aes.Mode = CipherMode.ECB;
ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
byte[] data = File.ReadAllBytes(@"C:\enc.aes");
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Write))
{
cs.Write(data, 0, data.Length);
cs.FlushFinalBlock();
File.WriteAllBytes(@"C:\dec.txt", ms.ToArray());
}
}
}
}
}
Two errors that I face -
1 - "Length of the data to decrypt is invalid"
This happens at the FlushFinalBlock I guess.
2 - "'System.OutOfMemoryException' "
This happens for large files.
I have read through many pages similar but could not fix it for such a decryption.
Any help ?
Regards