Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between the HMAC signature and hashing directly?

Just out of curiosity, really... for example, in python,

hashlib.sha1("key" + "data").hexdigest() != hmac.new("key", "data", hashlib.sha1)

is there some logical distinction I'm missing between the two actions?

like image 771
Ben Avatar asked Jul 17 '12 16:07

Ben


2 Answers

hashlib.sha1 gives you simply sha1 hash of content "keydata" that you give as a parameter (note that you are simply concatenating the two strings). The hmac call gives you keyed hash of the string "data" using string "key" as the key and sha1 as the hash function. The fundamental difference between the two calls are that the HMAC can only be reproduced if you know the key so you would also know something about who has generated the hmac. SHA1 can only be used to detect that content has not changed.

like image 160
Jari Avatar answered Sep 22 '22 16:09

Jari


I found the answer in the manual.

https://en.wikipedia.org/wiki/Hmac#Design_principles

like image 24
Ben Avatar answered Sep 24 '22 16:09

Ben