小编emm*_*uel的帖子

在EOF抛出异常之前停止解密:填充无效且无法删除

这就是我们拥有的场景:我们有大量的加密文件,大约为千兆字节,如果我们读到它们,我们可以正确解密.当我们读取并检测文件中的某个标志时会出现问题,然后我们停止读取并调用reader.Close(),会发生CryptographicException:"Padding无效且无法删除".被扔了.我有这个小控制台应用程序重现这种行为,测试它只是运行它,它将在你的C:\驱动器中创建一个文件然后按任意键时将逐行读取,并在按'q'时停止.

using System;
using System.IO;
using System.Security.Cryptography;

namespace encryptSample
{
    class Program
    {
        static void Main(string[] args)
        {
            var transform = CreateCryptoTransform(true);
            // first create encrypted file
            using (FileStream destination = new FileStream("c:\\test_enc.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
            {
                using (CryptoStream cryptoStream = new CryptoStream(destination, transform, CryptoStreamMode.Write))
                {
                    using (StreamWriter source = new StreamWriter(cryptoStream))
                    {
                        for (int i = 0; i < 1000; i++)
                        {
                            source.WriteLine("This is just random text to fill the file and show what happens when I stop reading …
Run Code Online (Sandbox Code Playgroud)

c# encryption aes encryption-symmetric

9
推荐指数
2
解决办法
2144
查看次数

标签 统计

aes ×1

c# ×1

encryption ×1

encryption-symmetric ×1