Created
July 5, 2013 01:17
-
-
Save robbles/5931074 to your computer and use it in GitHub Desktop.
HMAC signatures for API requests in different languages
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
var crypto = require('crypto'); | |
var message = 'GET /foo/bar?arg1=aaaa&arg2=bbbb'; | |
var secret = 'secret'; | |
crypto.createHmac('sha256', secret).update(message).digest('base64'); | |
// '82LHSJc4h/5BpLrBcGyWjTIiLuJTBYkgyGAb7cNmXew=' |
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
<?php | |
$message = 'GET /foo/bar?arg1=aaaa&arg2=bbbb'; | |
$secret = 'secret'; | |
$signature = base64_encode(hash_hmac('sha256', $message, $secret, true)); | |
echo $signature; | |
# 82LHSJc4h/5BpLrBcGyWjTIiLuJTBYkgyGAb7cNmXew= |
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 | |
message = 'GET /foo/bar?arg1=aaaa&arg2=bbbb' | |
secret = 'secret' | |
hmac.new(key=secret, msg=message, digestmod=hashlib.sha256).digest().encode('base64').strip() | |
# '82LHSJc4h/5BpLrBcGyWjTIiLuJTBYkgyGAb7cNmXew=' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment