diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-02-03 09:37:04 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-02-03 09:37:04 -0600 |
| commit | 6df03a2dbe92c84309553661bec24873f5b5d204 (patch) | |
| tree | 9171fb0addbe2c056db2a04131c098be76a48d30 /src | |
| parent | 40b858f4710a3762390cfa0eb9415caeaa6ed39e (diff) | |
| download | slskd-6df03a2dbe92c84309553661bec24873f5b5d204.tar.gz | |
add ToSHA1
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> |
