各位大哥,我在使用TripleDESCryptoServiceProvider加密的时候,不知道为什么,我输入的字节流是64字节而加密之后返回的却是72字节,是什么原因啊??各位帮帮忙啊。加解密算法如下:
public byte[] EncryptBytes(byte[] plainBytes, byte[] key, byte[] iv)
{
try
{
TripleDESCryptoServiceProvider tds = new TripleDESCryptoServiceProvider();
// tds.Padding = PaddingMode.None;
ICryptoTransform ct = tds.CreateEncryptor(key, iv);
MemoryStream ms = new MemoryStream();
CryptoStream cStream = new CryptoStream(ms,
ct,
CryptoStreamMode.Write);
cStream.Write(plainBytes, 0, plainBytes.Length);
cStream.FlushFinalBlock();
byte[] ret = ms.ToArray();
cStream.Close();
ms.Close();
return ret;
}
catch
{
return plainBytes;
}
}
public byte[] DecryptBytes(byte[] encryptBytes, byte[] key, byte[] iv)
{
try
{
TripleDESCryptoServiceProvider tds = new TripleDESCryptoServiceProvider();
// tds.Padding = PaddingMode.None;
ICryptoTransform ct = tds.CreateEncryptor(key, iv);
MemoryStream msDecrypt = new MemoryStream(encryptBytes);
CryptoStream cStream = new CryptoStream(msDecrypt,
ct,
CryptoStreamMode.Read);
byte[] fromEncrypt = new byte[encryptBytes.Length];
cStream.Read(fromEncrypt, 0, fromEncrypt.Length);
//cStream.FlushFinalBlock();
//msDecrypt.Close();
//cStream.Close();
return fromEncrypt;
}
catch
{
return encryptBytes;
}
}