首页 新闻 会员 周边 捐助

TripleDESCryptoServiceProvider加密问题

0
悬赏园豆:30 [已关闭问题] 关闭于 2011-08-13 12:08

各位大哥,我在使用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;
}
}

Raysonxin的主页 Raysonxin | 初学一级 | 园豆:13
提问于:2011-08-12 12:39
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册