引用:
using System.Security.Cryptography;
类:
public class MD5Util
{
public static string GetMD5(string input)
{
return GetMD5(input, Encoding.Default);
}
public static string GetMD5(string input, Encoding encoding)
{
using (MD5 md5Hash = MD5.Create())
{
byte[] data = md5Hash.ComputeHash(encoding.GetBytes(input));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sb.Append(data[i].ToString("x2"));
}
return sb.ToString();
}
}
}
/// <summary> /// MD5大写 UTF8编码 /// </summary> /// <returns></returns> public static string GetMD5(string orgStr) { using (System.Security.Cryptography.MD5 m = System.Security.Cryptography.MD5.Create()) { byte[] hashData = m.ComputeHash(Encoding.UTF8.GetBytes(orgStr)); return System.BitConverter.ToString(hashData).Replace("-", "").ToUpper(); } }