Skip to content

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

class method

OpenSSL::Digest.new

Digest.new(string [, data]) → Digest

Creates a Digest instance based on string, which is either the ln (long name) or sn (short name) of a supported digest algorithm.

If data (a String) is given, it is used as the initial input to the Digest instance, i.e.

Example
digest = OpenSSL::Digest.new('sha256', 'digestdata')

is equivalent to

Example
digest = OpenSSL::Digest.new('sha256')
digest.update('digestdata')
See also .digest #<< #block_length also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1