Is a hmac-sha1 hash always 20 bytes long? Python code

user667674 picture user667674 · Jul 30, 2011 · Viewed 10.1k times · Source

Is the digest always 20 bytes long? len(hashed.digest()) seems to always be 20.

hashed = hmac.new(key, signature_base_string, sha)
print hashed.digest()
print len(hashed.digest())
i = 0
for c in hashed.digest():
    i = i + 1
    print ord(c)
print base64.b64encode(hashed.digest())

Answer

Keith picture Keith · Jul 30, 2011

All hashing functions have fixed length outputs. SHA1 is 160 bits, or 20 bytes.