You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
|
|
|
|
|
|
namespace CommonFunc
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// MD5Provider 的摘要说明
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class MD5Provider
|
|
|
|
|
|
{
|
|
|
|
|
|
private MD5Provider()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 计算指定字符串的MD5哈希值
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="message">要进行哈希计算的字符串</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static string Hash(string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(message))
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MD5 md5 = MD5.Create();
|
|
|
|
|
|
byte[] source = Encoding.UTF8.GetBytes(message);
|
|
|
|
|
|
byte[] result = md5.ComputeHash(source);
|
|
|
|
|
|
StringBuilder buffer = new StringBuilder(result.Length);
|
|
|
|
|
|
return BitConverter.ToString(result).Replace("-", "").ToLower();
|
|
|
|
|
|
//for (int i = 0; i < result.Length; i++)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// buffer.Append(result[i].ToString("x2"));//将byte值转换成十六进制字符串
|
|
|
|
|
|
//}
|
|
|
|
|
|
//return buffer.ToString() ;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|