Skip to content

Instantly share code, notes, and snippets.

Created August 21, 2016 23:27
Show Gist options
  • Save anonymous/6da0e6bba7a49ea5b867c4fed46006f0 to your computer and use it in GitHub Desktop.
Save anonymous/6da0e6bba7a49ea5b867c4fed46006f0 to your computer and use it in GitHub Desktop.
def sign_data(self, data=None):
signature = hmac.new(self._token, msg=bytes(self._user, 'utf8'), digestmod=hashlib.sha512)
if data:
signature.update(bytes(json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')),'utf8'))
signed_data = {'user' : self._user, 'signature' : signature.hexdigest()}
if data != None:
signed_data['data'] = data
return signed_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment