Created
December 14, 2012 08:15
-
-
Save samwize/4283587 to your computer and use it in GitHub Desktop.
Compute signature of a http from Hoiio. This is used to authenticate the notification from Hoiio. Match this computed signature with the HTTP header "X-Hoiio-Signature".
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 | |
def sign(payload, key): | |
dig = hmac.new(key, msg=payload, digestmod=hashlib.sha256).digest() | |
return dig.encode('hex') | |
if __name__ == "__main__": | |
import sys | |
if (len(sys.argv) == 3): | |
payload = sys.argv[1]; | |
accessToken = sys.argv[2]; | |
else: | |
# Example | |
payload = 'to=%2B6511111111&dest=&session=S32&tag=&call_state=ringing&from=%2B6522222222&txn_ref=AA-C-1000000' | |
accessToken = 'AAAAAAAAAAAAAAAA' | |
print "Computed Signature: " + sign(payload, accessToken) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment