8

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())

3 Answers3

11

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

Keith
  • 42,110
  • 11
  • 57
  • 76
2

Yes. SHA1 HMAC hash is always 160 bits (e.g. 20 bytes).

MByD
  • 135,866
  • 28
  • 264
  • 277
2

SHA-1 always returns 160 bits, or 20 bytes.

http://www.itl.nist.gov/fipspubs/fip180-1.htm

"For a message of length < 2^64 bits, the SHA-1 produces a 160-bit condensed representation of the message called a message digest."

Joe
  • 41,484
  • 20
  • 104
  • 125