using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace EShang.Common { /// /// SHA1签名相关方法 /// public class SHA1Util { /// /// SHA1签名 /// /// /// public static string SHA1Signature(string input) { using (SHA1 sha1Hash = SHA1.Create()) { // 将输入字符串转换为字节数组 byte[] inputBytes = Encoding.UTF8.GetBytes(input); // 计算输入的 SHA1 哈希值 byte[] hashBytes = sha1Hash.ComputeHash(inputBytes); // 将哈希字节数组转换为十六进制字符串 StringBuilder hashStringBuilder = new StringBuilder(); foreach (byte b in hashBytes) { hashStringBuilder.Append(b.ToString("x2")); } // 返回 SHA1 签名的十六进制字符串 return hashStringBuilder.ToString(); } } } }