24 lines
659 B
C#
24 lines
659 B
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace MasstransferCommon.Utils;
|
|
|
|
/// <summary>
|
|
/// MD5 加密工具类
|
|
/// </summary>
|
|
public class Md5Util
|
|
{
|
|
public static string Md5(string input)
|
|
{
|
|
// 创建一个MD5对象
|
|
// 将输入字符串转换为字节数组
|
|
var inputBytes = Encoding.UTF8.GetBytes(input);
|
|
// 计算输入字节数组的哈希值
|
|
var bytes = MD5.HashData(inputBytes);
|
|
// 将字节数组转换为字符串
|
|
var hashString = new StringBuilder();
|
|
foreach (var b in bytes) hashString.Append($"{b:x2}");
|
|
|
|
return hashString.ToString();
|
|
}
|
|
} |