1# Python program to find SHA256 hash string of a file
2import hashlib
3
4filename = input("Enter the input file name: ")
5sha256_hash = hashlib.sha256()
6with open(filename,"rb") as f:
7 # Read and update hash string value in blocks of 4K
8 for byte_block in iter(lambda: f.read(4096),b""):
9 sha256_hash.update(byte_block)
10 print(sha256_hash.hexdigest())
11
1import hmac
2import hashlib
3import base64
4dig = hmac.new(b'1234567890', msg=your_bytes_string, digestmod=hashlib.sha256).digest()
5base64.b64encode(dig).decode() # py3k-mode
6'Nace+U3Az4OhN7tISqgs1vdLBHBEijWcBeCqL5xN9xg='
7
1# python 2
2import hmac
3import hashlib
4
5nonce = 1234
6customer_id = 123232
7api_key = 2342342348273482374343434
8API_SECRET = 892374928347928347283473
9
10message = '{} {} {}'.format(nonce, customer_id, api_key)
11signature = hmac.new(
12 str(API_SECRET),
13 msg=message,
14 digestmod=hashlib.sha256
15).hexdigest().upper()
16
17print signature
18