zhao_js
2023-11-28 4d2bb20eecf42af8c0b29fda38b02df0f6c9895d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
 
namespace AlibabaSDK.Setting
{
    public class AlibabaPlatHelper
    {
        /// <summary>
        /// 验签,防篡改
        /// </summary>
        /// <param name="message"></param>
        /// <param name="_aop_signature"></param>
        /// <returns></returns>
        public static bool MsgCheckSign(string message, string aop_signature)
        {
            string tmp = $"message{message}";
            byte[] signatureKey = Encoding.UTF8.GetBytes(AlibabaApiSet.SignKey);
            HMACSHA1 hmacsha1 = new HMACSHA1(signatureKey);
            byte[] hashBytes = hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(tmp));
            byte[] hash = hmacsha1.Hash;
            //TO HEX
            string sign = BitConverter.ToString(hashBytes).Replace("-", "").ToUpper();
            return sign == aop_signature;
        }
    }
}