在python中使用sha512签名消息

时间:2017-04-01 16:41:08

标签: python hmac sha512

我试图通过hitbtc.com上的websocket发送消息。从api文档中," signagure"需要是一个基于哈希的消息认证代码:base64 hmac-sha512(消息的二进制表示)"

我收到错误消息:' str'对象没有属性< hexdigest'

    import time
    import json
    import hmac
    import hashlib
    def sign(payload):
                key = ""
                secret = ""
                """
                Signature method which wraps signature and nonce parameters around a
                payload dictionary.
                :param payload:
                :return:
                """
                nonce = str(int(time.time() * 1000))
                package = {'apikey': key,
                           'message': {'nonce': nonce, 'payload': payload}}

                signature = hmac.new(secret, json.dumps(payload).hexdigest,
                                     hashlib.sha512).hexdigest()
                package['signature'] = signature

                return json.dumps(package)
payload = {"Login": {}}
s = sign(payload)

0 个答案:

没有答案