Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is a SHA-1 Hash 40 characters long if it is only 160 bit?

The title of the question says it all. I have been researching SHA-1 and most places I see it being 40 Hex Characters long which to me is 640bit. Could it not be represented just as well with only 10 hex characters 160bit = 20byte. And one hex character can represent 2 byte right? Why is it twice as long as it needs to be? What am I missing in my understanding.

And couldn't an SHA-1 be even just 5 or less characters if using Base32 or Base36 ?

like image 226
AGrunewald Avatar asked Sep 13 '10 20:09

AGrunewald


People also ask

Is SHA1 always 40 characters?

In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographically broken but still widely used hash function which takes an input and produces a 160-bit (20-byte) hash value known as a message digest – typically rendered as 40 hexadecimal digits.

How long is a SHA1 hash?

The hash size for the SHA1 algorithm is 160 bits.

How many characters is a SHA1 hash?

The length of a SHA1 hash is 160 bits or 20 bytes. In this application it is represented by 40 characters in hexadecimal form.

Is SHA1 always the same length?

SHA-1 produces a 160-bit (20-byte) hash value known as a message digest. A SHA-1 hash value is typically rendered as a hexadecimal number, 40 digits long.


Video Answer


1 Answers

One hex character can only represent 16 different values, i.e. 4 bits. (16 = 24)

40 × 4 = 160.


And no, you need much more than 5 characters in base-36.

There are totally 2160 different SHA-1 hashes.

2160 = 1640, so this is another reason why we need 40 hex digits.

But 2160 = 36160 log362 = 3630.9482..., so you still need 31 characters using base-36.

like image 99
kennytm Avatar answered Sep 21 '22 11:09

kennytm