C# MD5加密
程序员文章站
2024-03-19 22:15:28
...
/// <summary>
/// 返回MD5加密字符串
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string getMd5(string str)
{
if (str == null)
return null;
string result = "";
MD5 md5 = MD5.Create();
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
for (int i = 0; i < s.Length; i++)
{
result+=s[i].ToString("X2");
}
return result;
}