add md5 hash for single string

This commit is contained in:
_nebula 2024-02-14 01:42:47 +00:00
parent efc6964d7e
commit b04a593939

View File

@ -239,6 +239,22 @@ public static class Extensions
return sb.ToString(); return sb.ToString();
} }
public static string GetMD5Hash(this string input)
{
using var md5 = System.Security.Cryptography.MD5.Create();
var bytes = Encoding.ASCII.GetBytes(input);
var hashBytes = md5.ComputeHash(bytes);
var sb = new StringBuilder();
for (var i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
/// <summary> /// <summary>
/// only works for c# serializable objects /// only works for c# serializable objects
/// </summary> /// </summary>