From 6df03a2dbe92c84309553661bec24873f5b5d204 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 3 Feb 2022 09:37:04 -0600 Subject: add ToSHA1 --- src/slskd/Common/Extensions.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index ebf16fce..736d8863 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -25,6 +25,7 @@ namespace slskd using System.Net.Sockets; using System.Numerics; using System.Reflection; + using System.Security.Cryptography; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; @@ -325,6 +326,17 @@ namespace slskd obj.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(Dictionary<,>)); } + /// + /// Returns the SHA1 hash of the input string. + /// + /// The string to hash. + /// The computed SHA1 hash. + public static string ToSHA1(this string str) + { + using var sha = SHA1.Create(); + return BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(str))).Replace("-", string.Empty); + } + /// /// Redacts this instance of Options, replacing properties marked with with '*****'. /// -- cgit v1.2.3