diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 12 |
1 files changed, 12 insertions, 0 deletions
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; @@ -326,6 +327,17 @@ namespace slskd } /// <summary> + /// Returns the SHA1 hash of the input string. + /// </summary> + /// <param name="str">The string to hash.</param> + /// <returns>The computed SHA1 hash.</returns> + public static string ToSHA1(this string str) + { + using var sha = SHA1.Create(); + return BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(str))).Replace("-", string.Empty); + } + + /// <summary> /// Redacts this instance of Options, replacing properties marked with <see cref="SecretAttribute"/> with '*****'. /// </summary> /// <remarks> |
