Name

MD5 — MD5 message digest class

Synopsis

The MD5 class provides a one-way hash function from arbitrary text data by using the algorithm described in RFC-1321

Example

requires 'md5'

md5 = MD5::new("matz")
puts md5.hexdigest # prints: 3eb50a8d683006fdf941b9860798f9aa

Class Methods

MD5::new([str])
MD5::md5([str])

Creates a new MD5 object. If a string argument is given, it’s added to the object.

Instance Methods

md.clone

Copies the MD5 object.

md.digest

Returns the MD5 hash of the added strings as a string of 16 bytes.

md.hexdigest

Returns the MD5 hash of the added strings as a string of 32 hexadecimal digits.

md.update(str)
md << str

Updates the MD5 object with the string str. Repeated calls are equivalent to a single call with the concatenation of all the arguments, i.e., m.update(a); m.update(b) is equivalent to m.update(a+b), and m << a << b is equivalent to m << a+b.

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.