62,243
社区成员




using System.Text;
using System.Security.Cryptography;
public static string GetSignByHmacMd5(string key, string code)
{
byte[] keyBytes = Encoding.Default.GetBytes(key);
byte[] hasCodeBytes = Encoding.Default.GetBytes(code);
string result = string.Empty;
using (HMACMD5 hmac = new HMACMD5(keyBytes))
{
byte[] hashValue = hmac.ComputeHash(hasCodeBytes);
result = string.Concat(hashValue.Select(b => b.ToString("x2")));
}
return result.ToUpper();
}
var bytes = Encoding.Default.GetBytes("abcd");
var hmacmd5 = new HMACMD5 { Key = bytes };
var hash = hmacmd5.ComputeHash(bytes);
var c = string.Concat(hash.Select(b => b.ToString("x2")));
Console.WriteLine(c);