mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-04-20 18:12:50 +08:00
..
This commit is contained in:
parent
75f426105f
commit
ee90ca9f41
@ -5,13 +5,14 @@
|
||||
// @created: 07/26/2022 21:57
|
||||
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SshNet.Security.Cryptography;
|
||||
using HMACMD5 = System.Security.Cryptography.HMACMD5;
|
||||
using MD5 = SshNet.Security.Cryptography.MD5;
|
||||
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
@ -255,6 +256,37 @@ public static class StringExtensions
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 对一个字符串进行sha1 hash运算
|
||||
/// </summary>
|
||||
/// <param name="me">字符串</param>
|
||||
/// <param name="e">字符串使用的编码</param>
|
||||
/// <returns>hash摘要的16进制文本形式(无连字符小写)</returns>
|
||||
public static string Sha1(this string me, Encoding e)
|
||||
{
|
||||
using var sha1 = SHA1.Create();
|
||||
return BitConverter.ToString(sha1.ComputeHash(e.GetBytes(me)))
|
||||
.Replace("-", string.Empty)
|
||||
.ToLower(CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对一个字符串进行sha1 hash运算
|
||||
/// </summary>
|
||||
/// <param name="me">对一个字符串进行sha1 hash运算</param>
|
||||
/// <param name="secret">密钥</param>
|
||||
/// <param name="e">使用的编码</param>
|
||||
/// <returns>hash摘要的16进制文本形式(无连字符小写)</returns>
|
||||
public static string HmacSha1(this string me, string secret, Encoding e)
|
||||
{
|
||||
using var hmacSha1 = new HMACSHA1(e.GetBytes(secret));
|
||||
|
||||
return BitConverter.ToString(hmacSha1.ComputeHash(e.GetBytes(me)))
|
||||
.Replace("-", string.Empty)
|
||||
.ToLower(CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 对一个字符串进行md5hash运算
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user