问题
I am using this code to encrypt a 8 bytes PlainText with a 8 bytes Key but the result is always a 16 bytes array.
public static byte[] Encrypt(byte[] PlainText, byte[] key)
{
MemoryStream ms = new MemoryStream();
DESCryptoServiceProvider mDES = new DESCryptoServiceProvider();
mDES.Mode = CipherMode.ECB;
mDES.Key = key;
CryptoStream encStream = new CryptoStream(ms, mDES.CreateEncryptor(), CryptoStreamMode.Write);
BinaryWriter bw = new BinaryWriter(encStream);
bw.Write(PlainText);
bw.Close();
encStream.Close();
byte[] buffer = ms.ToArray();
ms.Close();
return buffer;
}
The first 8 bytes of the ouptut is what I expect but the rest I don't what it is.. is it something wrong with this code?
回答1:
The input will be padded to the next block size using PKCS padding. 7 bytes input will be padded to 8. 8-15 to 16. 16-23 to 24 and so on and so forth.
来源:https://stackoverflow.com/questions/1262594/des-encryption-of-8-bytes-plain-text-results-in-16-bytes-array