简体   繁体   中英

C# CryptoStream result not as expected

I'm trying to understand why the following code results in the encrypted byte array being 16 bytes if plainText is 8 bytes in length. I expected the result to also be 8 bytes in length?

private static byte[] encrypt(byte[] key, byte[] plainText)
{
    try
    {
        using (MemoryStream ms = new MemoryStream())
        {
            DES des = new DESCryptoServiceProvider() { Key = key, IV = key };

            using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
            {
                using(BinaryWriter bw = new BinaryWriter(cs))
                {
                    bw.Write(plainText);
                }
            }

            return ms.ToArray();
        }
    }
    catch (Exception e)
    {
        Logger.LogWarning(e);
        throw e;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM