1.创建一个类
namespace SmArtHoTel.RBACcrud.User
{
public static class Md5Helper
{
public static string Md5Id(string input)
{
string password = input;
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
using (MD5 md5 = MD5.Create())
{
// 计算哈希值
byte[] hashBytes = md5.ComputeHash(passwordBytes);
// 将结果转换为十六进制字符串
string hash = BitConverter.ToString(hashBytes).Replace("-", "").ToUpper();
return hash;
}
}
public static string Md5(this string input)
{
string password = input;
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
using (MD5 md5 = MD5.Create())
{
// 计算哈希值
byte[] hashBytes = md5.ComputeHash(passwordBytes);
// 将结果转换为十六进制字符串
string hash = BitConverter.ToString(hashBytes).Replace("-", "").ToUpper();
return hash;
}
}
}
}