Created
September 8, 2022 03:56
-
-
Save prabalsslw/facfa1c0ae8b0dd09a22a878e5430eb4 to your computer and use it in GitHub Desktop.
bKash RPP Webhook Signature Validation
This file contains hidden or 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 base64 | |
import hashlib | |
import hmac | |
sig = '' // Signature from the payload header | |
payl = '' // Webhook payload from the body | |
key = '' // API Key provided by organization | |
def is_valid_signature(signature, payload, api_key): | |
signature = base64.urlsafe_b64decode(signature) | |
print('Signature:') | |
print(signature) | |
key = base64.urlsafe_b64decode(api_key) | |
digest = hmac.new(key=key, msg=payload, digestmod=hashlib.sha256).digest() | |
print('Digest:') | |
print(digest) | |
return hmac.compare_digest(digest, signature) | |
print(is_valid_signature(sig, payl.encode('utf-8'), key)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment