What is the length of a hashed string with SHA512?
77,112
As the name implies, it's 512 bits, that is 64 bytes.
But that's the hash, maybe you're wondering about a specific representation of that hash in string, as is commonly used, then it depends of the given representation.
If you write the hash in hexa, then it will be 128 characters.
If you write the hash in base64, then it will be 86 bytes (or 88 with padding).
Author by
DjOnce
Updated on July 05, 2022Comments
-
DjOnce almost 2 years
Is the length of a string hashed with sha512 always the same?
If so, what is it?
-
gotqn almost 8 years
-
Michael Freidgeim over 4 yearsDoes this answer your question? What data type to use for hashed password field and what length?
-
-
DjOnce almost 11 yearswhich means 64 characters long?
-
Raymond Nijland almost 11 yearsif raw_output of the php hash function is true the outputted chars should be less.
-
Tiago almost 11 yearsthe default is hex - 128 characters
-
LalakaJ about 10 years@DjOnce, @dystroy It's been a while since this question has been answered. But thought I should add something here. In case you are trying to design the database tables to store the hash value. Run this in MySQL to get the length:
length(sha2('password',512));
. This will give you the length as 128. -
conceptdeluxe over 9 yearsThough dystroys anwswer is perfectly valid, note that in terms of session.hash_bits_per_character the hash length may vary based on the bits per character set at php.ini - see: php.net/manual/en/… and stackoverflow.com/a/17032075/1510754
-
Andrew Theken about 8 years@DjOnce, not really 64 chars long, as some of those bytes could map to "unprintable" characters (such as nul, or control chars, etc..)
-
Eric over 6 yearsYou mean
86 characters
not86 bytes
, right? Since in some language (e.g java) each char is not just 1 byte. And, seems in Java it's always pad out as string of length 88. -
Denys Séguret over 6 years@EricWang You use base64 when exchanging, in context where it makes sense. If you're interested in storing hash in the memory of a java program, don't use base64, use the standard byte representation.
-
Eric over 6 years@DenysSéguret In my case, the base64 string is stored in some database, but Java program need to read it, then decode as key (bytes), then do some validation.
-
Denys Séguret over 6 years@EricWang base64 encoding should really be used only when needed, for example in URIs. In all other cases just use byte arrays.