1 /// <summary> 2 /// HMAC加密 3 /// </summary> 4 /// <param name="EncryptText">加密內容</param> 5 /// <param name="EncryptKey">密鑰</param> 6 /// <returns></returns> 7 public static string ToHMacSha1(string EncryptText, string EncryptKey) 8 { 9 string result = ""; 10 11 try 12 { 13 HMACSHA1 hmacsha1 = new HMACSHA1(); 14 hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey); 15 byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText); 16 byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer); 17 18 result = Convert.ToBase64String(hashBytes); 19 } 20 catch (Exception ex) 21 { 22 23 } 24 25 return result; 26 }
【原文出處】http://www.51aras.com/?id=9