.net与java HMACSHA1签名加密问题解决方案

 /// <summary>
        /// HMACSHA1签名
        /// </summary>
        /// <param name="EncryptText">签名内容</param>
        /// <param name="EncryptKey">密钥</param>
        /// <returns></returns>
        public static string HMACSHA1Text(string EncryptText, string EncryptKey)
        { 
            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);
            return Convert.ToBase64String(hashBytes);
        }

如上,最终获取到的签名 和https://1024tools.com/hmac上面的保持一致 即正确;

posted @ 2021-08-27 09:55  黑默丁格  阅读(349)  评论(0编辑  收藏  举报