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

Share:
77,112
DjOnce
Author by

DjOnce

Updated on July 05, 2022

Comments

  • DjOnce
    DjOnce almost 2 years

    Is the length of a string hashed with sha512 always the same?

    If so, what is it?

  • DjOnce
    DjOnce almost 11 years
    which means 64 characters long?
  • Raymond Nijland
    Raymond Nijland almost 11 years
    if raw_output of the php hash function is true the outputted chars should be less.
  • Tiago
    Tiago almost 11 years
    the default is hex - 128 characters
  • LalakaJ
    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
    conceptdeluxe over 9 years
    Though 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
    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
    Eric over 6 years
    You mean 86 characters not 86 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
    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
    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
    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.