Skip to content

Instantly share code, notes, and snippets.

@jaychoo
Forked from heskyji/hmac_sha1.py
Created April 28, 2022 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaychoo/6f54df8a0d39bcbfc9814e799a140576 to your computer and use it in GitHub Desktop.
Save jaychoo/6f54df8a0d39bcbfc9814e799a140576 to your computer and use it in GitHub Desktop.
Generate HMAC-SHA1 Signature using Python 3
import hashlib
import hmac
import base64
def make_digest(message, key):
key = bytes(key, 'UTF-8')
message = bytes(message, 'UTF-8')
digester = hmac.new(key, message, hashlib.sha1)
#signature1 = digester.hexdigest()
signature1 = digester.digest()
#print(signature1)
#signature2 = base64.urlsafe_b64encode(bytes(signature1, 'UTF-8'))
signature2 = base64.urlsafe_b64encode(signature1)
#print(signature2)
return str(signature2, 'UTF-8')
result = make_digest('message', 'private-key')
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment