Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computing an HMAC-SHA signature

I'm writing a module for Amazon's SimpleDB. They require REST requests to be signed using HMAC-SHA algorithm. (Details here.)

I'm told that there is a function to computer this signature, but I can't find it in the documentation. What is the function called, and what do its arguments look like?

like image 220
Steve Nay Avatar asked Nov 28 '25 01:11

Steve Nay


2 Answers

EDITED: The following should work:

pre {
  message = "Four score and seven years ago";
  key = "Abe Lincoln";
  signature = math:hmac_sha256_base64(message, key);
}
notify("Signature is", signature);

The function is math:hmac_sha256_base64(<datastring>,<keystring>)

like image 148
Randall Bohn Avatar answered Nov 30 '25 23:11

Randall Bohn


The HMAC is a standard function that can be found in crypto libraries for most platforms. Amazon shows several examples on the documentaion page you link to.

For Java, you can find it in javax.crypto.Mac

For .Net, look in System.Security.Cryptography

For KRL, I haven't found any built-in stock solution. Since it seems possible to embed javascript, the jsSHA implemenation could be useful. There is a sha1 function in the math library, and implementing HMAC according to RFC2104 doesn't seem that difficult.

like image 43
Anders Lindahl Avatar answered Nov 30 '25 23:11

Anders Lindahl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!