c# HMACSHA1 加密 返回16进制

        /// <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;
        }

 

posted @ 2019-06-14 16:33  路边有一棵草  阅读(949)  评论(0编辑  收藏  举报