hash_hmac sha512 authentication in python

  • Last Update :
  • Techknowledgy :

If somebody interesting, I've solve this by myself.

#!/usr/bin/python

import hashlib
import hmac
import requests
import time

apikey = '';
apisecret = '';

def request_comkort(url, payload):
   tosign = "&".join([i + '=' + payload[i]
      for i in payload
   ])
sign = hmac.new(apisecret, tosign, hashlib.sha512);
headers = {
   'sign': sign.hexdigest(),
   'nonce': int(time.time()),
   'apikey': apikey
}
r = requests.post(url, data = payload, headers = headers)
return r.text

# Get balance
print request_comkort("https://api.comkort.com/v1/private/user/balance";, {})
# Get Open Orders
print request_comkort("https://api.comkort.com/v1/private/order/list";, {
   'market_alias': "DOGE_LTC"
})
# Make Ask
print request_comkort("https://api.comkort.com/v1/private/order/sell";, {
   'market_alias': "HTML_DOGE",
   "amount": "1000",
   "price": "123123"
})
# Cancel order
print request_comkort("https://api.comkort.com/v1/private/order/cancel";, {
   'order_id': 10943
})

Suggestion : 2

hmac - Hash-based Message Authentication Code using Python ¶ The HMAC is an algorithm that generates a hash of the message using a cryptographic hash function and a secret cryptographic key. It can be used to check data for integrity and authenticity. ,  › Python generic classes ,  › Object classification codes manual , 5 days ago This video shows how to generate a hash digest in python.


https: //bittrex.com/api/v1.1/account/getbalance?apikey=API_KEY&currency=BTC 
https: //bittrex.com/api/v1.1/account/getbalance?apikey=API_KEY&currency=BTC 
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
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()

Suggestion : 3

A fast implementation of pbkdf2_hmac is available with OpenSSL. The Python implementation uses an inline version of hmac. It is about three times slower and doesn’t release the GIL.,This module implements a common interface to many different secure hash and message digest algorithms. Included are the FIPS secure hash algorithms SHA1, SHA224, SHA256, SHA384, and SHA512 (defined in FIPS 180-2) as well as RSA’s MD5 algorithm (defined in Internet RFC 1321). The terms “secure hash” and “message digest” are interchangeable. Older algorithms were called message digests. The modern term is secure hash.,The number of iterations should be chosen based on the hash algorithm and computing power. As of 2013, at least 100,000 iterations of SHA-256 are suggested.,Changed in version 3.1: The Python GIL is released to allow other threads to run while hash updates on data larger than 2047 bytes is taking place when using hash algorithms supplied by OpenSSL.

>>>
import hashlib
   >>>
   m = hashlib.sha256() >>>
   m.update(b "Nobody inspects") >>>
   m.update(b " the spammish repetition") >>>
   m.digest()
b '\x03\x1e\xdd}Ae\x15\x93\xc5\xfe\\\x00o\xa5u+7\xfd\xdf\xf7\xbcN\x84:\xa6\xaf\x0c\x95\x0fK\x94\x06' >>>
   m.digest_size
32
   >>>
   m.block_size
64
>>> hashlib.sha224(b "Nobody inspects the spammish repetition").hexdigest()
'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
>>> h = hashlib.new('ripemd160') >>>
   h.update(b "Nobody inspects the spammish repetition") >>>
   h.hexdigest()
'cc4a5ce1b3df48aec5d22d1f16b894a0b894eccc'
>>>
import hashlib, binascii
   >>>
   dk = hashlib.pbkdf2_hmac('sha256', b 'password', b 'salt', 100000) >>>
   binascii.hexlify(dk)
b '0394a2ede332c9a13eb82e9b24631604c31df978b4e2f0fbd2c549944f9d79a5'
>>> from hashlib
import blake2b
   >>>
   h = blake2b() >>>
   h.update(b 'Hello world') >>>
   h.hexdigest()
'6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'
>>> from hashlib
import blake2b
   >>>
   blake2b(b 'Hello world').hexdigest()
'6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'