Skip to content

Instantly share code, notes, and snippets.

@shashankmehra
Created September 11, 2018 07:35
Show Gist options
  • Save shashankmehra/7381be172ff324251e6ddcaee829aabc to your computer and use it in GitHub Desktop.
Save shashankmehra/7381be172ff324251e6ddcaee829aabc to your computer and use it in GitHub Desktop.
from hashlib import sha512
import base64
import hmac
def compute_signature(uri, params, token):
token = token.encode("utf-8")
s = uri
if len(params) > 0:
for k, v in sorted(params.items()):
if v:
s += k + str(v)
mac = hmac.new(token, s.encode("utf-8"), sha512)
computed = base64.b64encode(mac.digest())
return computed.strip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment