8位纯文本的DES加密结果为16字节数组 [英] DES encryption of 8 bytes plain text results in 16 bytes array
本文介绍了8位纯文本的DES加密结果为16字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这个代码来加密一个8字节的8字节的PlainText,但结果总是一个16字节的数组。
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;
}
ouptut的前8个字节是我期望的,但其余的我这个代码有什么问题吗?
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?
推荐答案
输入将被填充到下一个块大小使用 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.
这篇关于8位纯文本的DES加密结果为16字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文