using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace LiveForum.Code.Utility
{
///
///
///
public static class MD5Encryption
{
///
/// md5加密
///
///
///
public static string ToMD5(this string input)
{
// 创建一个 MD5 哈希算法的实例
using (MD5 md5 = MD5.Create())
{
// 将输入字符串转换为字节数组
byte[] inputBytes = Encoding.UTF8.GetBytes(input);
// 计算 MD5 哈希值
byte[] hashBytes = md5.ComputeHash(inputBytes);
// 将字节数组转换为十六进制字符串
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
}
// 返回哈希值字符串
return sb.ToString();
}
}
}
}