using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace ColdMint.scripts.utils; public class Md5Utils { /// /// Calculates the Md5 value of the file /// 计算文件的Md5值 /// /// /// public static string GetFileMd5(string filePath) { using (var md5 = MD5.Create()) { using (var stream = File.OpenRead(filePath)) { var hash = md5.ComputeHash(stream); return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } } } /// /// Calculates the Md5 value of the string /// 计算字符串的Md5值 /// /// /// public static string GetStringMd5(string str) { using (var md5 = MD5.Create()) { var hash = md5.ComputeHash(Encoding.UTF8.GetBytes(str)); return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } } }