C#AES加密生成的额外16个字节

时间:2020-02-17 07:54:53

标签: c# encryption aes

我正在使用以下代码测试C#AES加密,并且输出为32个字节而不是16个字节。我想了解额外的16个字节是什么。非常感谢您的帮助。

using System;
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;
using System.Text;

namespace TestEnc
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] key = { 50, 41, 132,234,143,17,
                       89, 74,   2, 56, 36,87,
                       54, 87,  88, 28};

            byte[] iv = { 45, 241,153,24,14,17,
                       8, 57,32,5,96,47,
                       54,87,88,8};
            using (Rijndael algorithm = Rijndael.Create())
            {
                algorithm.Padding = PaddingMode.PKCS7;
                using (ICryptoTransform encryptor = algorithm.CreateEncryptor(key, iv))
                {
                    string fullpath = @"c:\test.txt";
                    using (Stream FileOutStream = File.Open(fullpath, FileMode.Create))
                    {
                        using (Stream encStream = new CryptoStream(FileOutStream, encryptor, CryptoStreamMode.Write))
                        {
                            string s = "hello world 1234";
                            for (int i = 0; i < 1; i++)
                            {
                                encStream.Write(Encoding.ASCII.GetBytes(s), 0, (int)s.Length);
                            }
                        }

                    }
                }
            }
        }
    }
}

0 个答案:

没有答案
相关问题