From b04a593939ce313deee55c10d83398d296b6b3e9 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 14 Feb 2024 01:42:47 +0000 Subject: [PATCH] add md5 hash for single string --- QSB/Utility/Extensions.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/QSB/Utility/Extensions.cs b/QSB/Utility/Extensions.cs index 9677e30c..188abab7 100644 --- a/QSB/Utility/Extensions.cs +++ b/QSB/Utility/Extensions.cs @@ -239,6 +239,22 @@ public static class Extensions 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(); + } + /// /// only works for c# serializable objects ///