这是代码 -
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());
}
}
}
}
}
我面临的两个错误 -
1 - “要解密的数据长度无效”
我猜这发生在 FlushFinalBlock 上。
2 - “'System.OutOfMemoryException'”
这发生在大文件上。
我已经阅读了许多类似的页面,但无法为这样的解密修复它。
有什么帮助吗?
问候