HMAC-SHA1
Bash
The openssl package available in most linux distributions include a way of creating the HMAC-SHA1 string from the command line…
echo -n "string to sign" | openssl dgst -sha1 -hmac "my secret key"
(stdin)= a993876ea1218921a1c8551923473da7b310dfaeC\
Encoding encoding = Encoding.UTF8;
byte[] secretBytes = encoding.GetBytes(“my secret key”);
HMACSHA1 hmacsha1 = new HMACSHA1(secretBytes);
hmacsha1.ComputeHash(encoding.GetBytes(“string to sign”));
byte[] data = hmacsha1.Hash;Javascript
Cryptographic functions are available from the CryptJS libaray at https://code.google.com/p/crypto-js/.
var stringToSign = “string to sign”;
var secret = “my secret key”;
var signature = CryptoJS.HmacSHA1(stringToSign, secret);NodeJS
This code assumes you have the crypto-js library installed (npm install crypto-js)
Objective-C
HMAC-SHA1 functionality can be be included in IOS code by first adding the CommonCrypto library to your target, and including the following function in your appDelegate (or appropriate class)
PHP
Generating the HMAC-SHA1 in PHP can be done using the following code.
This will generate an encrypted hash of the string. In this case the string will be
a993876ea1218921a1c8551923473da7b310dfae
Ruby
Start up the ‘irb’ and try the following
Last updated