尝试为 3Commas 生成 HMAC SHA256 签名,我使用来自 official example 的相同参数,它应该生成:
“30f678a157230290e00475cfffccbc92ae3659d94c145a2c0e9d0fa28f41c11a”
但我生成:
“17a656c7df48fa2db615bfc719627fc94e59265e6af18cc7714694ea5b58a11a”
这是我尝试过的:
secretkey = 'NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j'
totalParams = '/public/api/ver1/accounts/new?type=binance&name=binance_account&api_key=XXXXXX&secret=YYYYYY'
print 'signature = '+hashlib.sha256((secretkey+totalParams).encode('ASCII')).hexdigest()
谁能帮我吗?
最佳答案
尝试使用 hmac
模块而不是 hashlib
模块:
import hmac
import hashlib
secret_key = b"NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
total_params = b"/public/api/ver1/accounts/new?type=binance&name=binance_account&api_key=XXXXXX&secret=YYYYYY"
signature = hmac.new(secret_key, total_params, hashlib.sha256).hexdigest()
print("signature = {0}".format(signature))
这给出了所需的结果:
signature = 30f678a157230290e00475cfffccbc92ae3659d94c145a2c0e9d0fa28f41c11a
关于python - 生成 HMAC SHA256 签名 Python,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53910845/