August 2018
Intermediate to advanced
366 pages
10h 14m
English
For this recipe, the following steps are to be performed:
import hashlib, hmac, time def compute_signature(message, secret): message = message.encode('utf-8') timestamp = str(int(time.time()*100)).encode('ascii') hashdata = message + timestamp signature = hmac.new(secret.encode('ascii'), hashdata, hashlib.sha256).hexdigest() return { 'message': message, 'signature': signature, 'timestamp': timestamp } def verify_signature(signed_message, secret): timestamp = signed_message['timestamp'] expected_signature = signed_message['signature'] ...