/// <summary> /// HMACSHA1 /// </summary> /// <param name="EncryptText"></param> /// <param name="EncryptKey"></param> /// <returns></returns> public static string HMACSHA1Text(string EncryptText, string EncryptKey) { //HMACSHA1加密 HMACSHA1 hmacsha1 = new HMACSHA1(); hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey); byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText); byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer); String result = BitConverter.ToString(hashBytes);//将运算结果转为string类型 result = result.Replace("-", "").ToUpper();//替换并转为大写 return result; }