Created
November 15, 2021 21:41
-
-
Save heneryville/281f090380ae94850b8b62c3f6c54230 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 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