8 字节纯文本的 DES 加密结果为 16 字节数组
我使用此代码使用 8 字节密钥加密 8 字节纯文本,但结果始终是 16 字节数组。
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;
}
输出的前 8 个字节是我所期望的,但其余的我不知道它是什么..这段代码有问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输入将使用 PKCS 填充 填充到下一个块大小。 7 个字节输入将被填充为 8。8-15 到 16。16-23 到 24 等等。
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.