using System.Security.Cryptography;
//byte[]转换为16进制
public static string ToHexString(byte[] bytes)
{
string hexString = string.Empty;
if (bytes != null)
{
StringBuilder strB = new StringBuilder();
foreach (byte b in bytes)
{
strB.AppendFormat("{0:x2}", b);
}
hexString = strB.ToString();
}
return hexString;
}
//MD5加密
public static string MD5Encrypt(string strText)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strText));
md5.Clear();
return ToHexString(result);
}