如何用Python签署HMAC-SHA512? [重复]

问题描述 投票:2回答:1

我想以下列格式进行获取请求:

https://bittrex.com/api/v1.1/account/getbalance?apikey=API_KEY&currency=BTC

我确实有公钥和密钥。但是我发现了以下声明:

对于此版本,我们使用标准HMAC-SHA512签名。将apikey和nonce附加到您的请求并计算HMAC哈希并将其包含在apisign标头下

我真的不知道如何正确加密我的密钥。使用普通密钥显然会返回“NONCE_NOT_PROVIDED”。我得到的一切都是这样的:

current_price = requests.get("https://bittrex.com/api/v1.1/account/getbalance?apikey=API_KEY&currency=BTC")

如何正确签名和加密密钥?谢谢。

编辑:

目前的尝试如下所示。

def getWalletSize():
    APIkey = b'29i52wp4'
    secret = b'10k84a9e'
    s = "https://bittrex.com/api/v1.1/account/getbalance?apikey=29i52wp4&currency=BTC"
    digest = hmac.new(secret, msg=s, digestmod=hashlib.sha512).digest()
    current_balance = requests.get(digest)
    return current_balance

但是它引发了错误Unicode-objects must be encoded before hashing

python python-3.x api sign sha
1个回答
3
投票
import hmac
import hashlib
import base64

API_KEY = 'public_key'
s = """GET https://bittrex.com/api/v1.1/account/getbalance?apikey=%s&currency=BTC""" % API_KEY

base64.b64encode(hmac.new("1234567890", msg=s, digestmod=hashlib.sha512).digest())

它签署了请求

digest = hmac.new(secret_key, msg=thing_to_hash, digestmod=hashlib.sha512).digest()

这在base64中编码

base64.b64encode(digest)
© www.soinside.com 2019 - 2024. All rights reserved.