Created
February 22, 2023 10:42
-
-
Save CryceTruly/6c79fcc9264203fd3ccc4801efc1873e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hmac | |
import hashlib | |
import json | |
def makeHash(): | |
secret = "zzdfQr_HSb41O-chk9MEDDeLr_snDO3EiEZ6i5IEwZkgEwdF0W3VTtIHIQsEx-TQe1TZHesmcRGnS5Ss9MyCDw" | |
payload = json.dumps( | |
{ | |
"phone_number": "254787876541", | |
"external_user_id": "123445" | |
} | |
, separators=(',', ':')) | |
hash = hmac.new(secret.encode(), payload.encode(), hashlib.sha512).hexdigest() | |
print(hash) | |
makeHash() | |
def verify(data, signature): | |
payload = json.dumps(data, separators=(',', ':')) | |
hash = hmac.new("<secret>".encode(), payload.encode(), hashlib.sha512).hexdigest() | |
return hmac.compare_digest(hash, signature) | |
# url = "http://localhost:3000" | |
# headers = {'Content-type': 'application/json', 'Accept': 'text/plain', 'signature': request.headers.get('X-Signature', None)} | |
# r = requests.post(url, data=json.dumps(data), headers=headers) | |
# print(r.json()) | |
# def makeHash(): | |
# payload = json.dumps( | |
# { | |
# "key1": "val1", | |
# "key2": "val2" | |
# } | |
# , separators=(',', ':')) | |
# hash = hmac.new("".encode(), payload.encode(), hashlib.sha512).hexdigest() | |
# print(hash) | |
# makeHash() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment