Skip to content

Commit

Permalink
add md5 hash for single string
Browse files Browse the repository at this point in the history
  • Loading branch information
misternebula committed Feb 14, 2024
1 parent efc6964 commit b04a593
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions QSB/Utility/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ public static string GetMD5Hash(this IEnumerable<string> list)
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>
/// only works for c# serializable objects
/// </summary>
Expand Down

0 comments on commit b04a593

Please sign in to comment.