Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. 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.2 · 3.1 · 3.0