Skip to content

Instantly share code, notes, and snippets.

@heneryville
Created November 15, 2021 21:41
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 heneryville/281f090380ae94850b8b62c3f6c54230 to your computer and use it in GitHub Desktop.
Save heneryville/281f090380ae94850b8b62c3f6c54230 to your computer and use it in GitHub Desktop.
import hmac
import hashlib
import base64
# Never hard-code secrets in public code
SECRET = bytes('DX5Q3XXaQ5VEGiW224Xwg5GLicKWGDw/+hw9YDYTCvk=', 'UTF8')
timestamp = '1635513507'
passed_signature = 'wnraKDv+Oh6FsBNtLt8c+Lp+L0CvFUnn4RZZFslteNw='
body = '{"events":[{"eventType":"XXX"}]}'
body_and_timestamp = bytes(timestamp+body, 'UTF8')
digest = hmac.new(SECRET, msg=body_and_timestamp, digestmod=hashlib.sha256).digest()
computed_signature = base64.b64encode(digest).decode()
assert computed_signature == passed_signature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment