/// <summary>
/// 解密
/// </summary>
/// <param name="text">要被解密字符</param>
/// <param name="sKey">密钥</param>
/// <returns></returns>
public static string Decrypt(this string text, string sKey)
{
var provider = new DESCryptoServiceProvider();
int num = text.Length / 2;
byte[] buffer = new byte[num];
try
{
for (int i = 0; i < num; i++)
{
int num3 = Convert.ToInt32(text.Substring(i * 2, 2), 0x10);
buffer[i] = (byte)num3;
}
}
catch
{
return string.Empty;
}
provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
try
{
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
}
catch
{
return string.Empty;
}
return Encoding.Default.GetString(stream.ToArray());
}