日期:2014-05-17 浏览次数:20707 次
///?<summary>????
///?解密数据????
///?</summary>??
///?<param?name="Text"></param>????
///?<param?name="sKey"></param>????
///?<returns></returns>??
public string DecryptString(string Text, string sKey,string sIV)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Mode = System.Security.Cryptography.CipherMode.CBC;
des.Padding = PaddingMode.Zeros;
int len;
len = Text.Length / 2;
byte[] inputByteArray = new byte[len];
int x, i;
for (x = 0; x < len; x++)
{
i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);
inputByteArray[x] = (byte)i;
}
byte[] kkey = ASCIIEncoding.UTF8.GetBytes(sKey);
byte[] iiv = ASCIIEncoding.UTF8.GetBytes(sIV;
des.Key = kkey;//+++这里报错 指定键的大小对于此算法无效。+++
des.IV = iiv;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Encoding.Default.GetString(ms.ToArray());
}