Digest is the base type of hashing algorithms like Digest::MD5, Digest::SHA1, Digest::SHA256, or Digest::SHA512.
A Digest instance holds the state of an ongoing hash calculation. It can receive new data to include in the hash via #update, #<<, or #file. Once all data is included, use #final or #hexfinal to get the hash. This will mark the ongoing calculation as finished. A finished calculation can't receive new data.
A digest.dup.final call may be used to get an intermediate hash value.
Use #reset to reuse the Digest instance for a new calculation.
Reads the io's data and updates the digest with it.
Returns the digest output size in bytes.
Reads the file's content and updates the digest with it.
Puts the final digest output into dst.
Returns the final digest output.
Stores the output digest of #digest_size bytes in dst.
Writes a hexadecimal-encoded digest to dst.
Writes a hexadecimal-encoded digest to IO.
Returns a hexadecimal-encoded digest in a new String.
Resets the state of this object.
Resets the object to it's initial state.
Reads the io's data and updates the digest with it.
Hashes data incrementally.
Reference
Reference
Reference
Object
Object
Object
Reads the io's data and updates the digest with it.
Reads the file's content and updates the digest with it.
Puts the final digest output into dst.
Faster than the Bytes allocating version. Use when hashing in loops.
#final or #hexfinal can only be called once and raises FinalizedError on subsequent calls.
NOTE .dup.final(dst) call may be used to get an intermediate hash value.
Returns the final digest output.
#final or #hexfinal can only be called once and raises FinalizedError on subsequent calls.
NOTE .dup.final call may be used to get an intermediate hash value.
Stores the output digest of #digest_size bytes in dst.
Writes a hexadecimal-encoded digest to dst.
Faster than the String allocating version. Use when hashing in loops.
#final or #hexfinal can only be called once and raises FinalizedError on subsequent calls.
NOTE .dup.final call may be used to get an intermediate hash value.
Writes a hexadecimal-encoded digest to IO.
Faster than the String allocating version.
#final or #hexfinal can only be called once and raises FinalizedError on subsequent calls.
NOTE .dup.final call may be used to get an intermediate hash value.
This method is restricted to a maximum digest size of 64 bits. Implementations that allow a larger digest size should override this method to use a larger buffer.
Returns a hexadecimal-encoded digest in a new String.
#final or #hexfinal can only be called once and raises FinalizedError on subsequent calls.
NOTE .dup.hexfinal call may be used to get an intermediate hash value.
Resets the state of this object. Use to get another hash value without creating a new object.
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/Digest.html