Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Digest::SHA2#digest_length

digest_obj.digest_length → Integer

Return the length of the hash value (the digest) in bytes.

Example
Digest::SHA256.new.digest_length * 8
# => 256
Digest::SHA384.new.digest_length * 8
# => 384
Digest::SHA512.new.digest_length * 8
# => 512

For example, digests produced by Digest::SHA256 will always be 32 bytes (256 bits) in size.

See also #block_length #reset #<< #update also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0