当前位置:首页 > 操作系统 > MacOs

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

 


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐