我试图理解为什么下面的代码导致加密的字节数组是 16 个字节(如果plainText
长度为 8 个字节)。我预计结果的长度也是 8 个字节?
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;
}
}