我试图理解为什么以下代码导致加密字节数组为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;
}
}