简体   繁体   English

hmac-sha1哈希总是20个字节长吗? Python代码

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

Is the digest always 20 bytes long? 摘要总是20个字节长吗? len(hashed.digest()) seems to always be 20. len(hashed.digest())似乎总是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())

All hashing functions have fixed length outputs. 所有散列函数都具有固定长度输出。 SHA1 is 160 bits, or 20 bytes. SHA1是160位,或20个字节。

Yes. 是。 SHA1 HMAC hash is always 160 bits (eg 20 bytes). SHA1 HMAC哈希值始终为160位(例如20个字节)。

SHA-1 always returns 160 bits, or 20 bytes. SHA-1总是返回160位或20个字节。

http://www.itl.nist.gov/fipspubs/fip180-1.htm 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." “对于长度<2 ^ 64位的消息,SHA-1产生一个160位压缩的消息表示,称为消息摘要。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM