Type:
Module

This module provides a framework for message digest libraries.

You may want to look at OpenSSL::Digest as it supports support more algorithms.

A cryptographic hash function is a procedure that takes data and return a fixed bit string : the hash value, also known as digest. Hash functions are also called one-way functions, it is easy to compute a digest from a message, but it is infeasible to generate a message from a digest.

Example

1
2
3
4
5
6
7
8
9
10
11
12
require 'digest'
 
# Compute a complete digest
sha256 = Digest::SHA256.new
digest = sha256.digest message
 
# Compute digest by chunks
sha256 = Digest::SHA256.new
sha256.update message1
sha256 << message2 # << is an alias for update
 
digest = sha256.digest

Digest algorithms

Different digest algorithms (or hash functions) are available :

HMAC

See FIPS PUB 198 The Keyed-Hash Message Authentication Code (HMAC)

RIPEMD-160

(as Digest::RMD160) see homes.esat.kuleuven.be/~bosselae/ripemd160.html

SHA1

See FIPS 180 Secure Hash Standard

SHA2 family

See FIPS 180 Secure Hash Standard which defines the following algorithms:

  • SHA512

  • SHA384

  • SHA256

The latest versions of the FIPS publications can be found here: csrc.nist.gov/publications/PubsFIPS.html

Additionally Digest::BubbleBabble encodes a digest as a sequence of consonants and vowels which is more recognizable and comparable than a hexadecimal digest. See en.wikipedia.org/wiki/Bubblebabble

file
  • References/Ruby on Rails/Ruby/Classes/Digest/Digest::Instance

file(name) Instance Public methods updates the digest with the contents of a

2025-01-10 15:47:30
base64digest!
  • References/Ruby on Rails/Ruby/Classes/Digest/Digest::Instance

base64digest!() Instance Public methods Returns the resulting hash value and

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Ruby/Classes/Digest/Digest::Instance

digest_obj.new â another_digest_obj Instance Public methods Returns a new,

2025-01-10 15:47:30
block_length
  • References/Ruby on Rails/Ruby/Classes/Digest/Digest::SHA2

digest_obj.block_length â Integer Instance Public methods Returns the block

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Ruby/Classes/Digest/Digest::HMAC

new(key, digester) Class Public methods Creates a

2025-01-10 15:47:30
update
  • References/Ruby on Rails/Ruby/Classes/Digest/Digest::SHA2

digest_obj.update(string) â digest_objdigest_obj Instance Public methods

2025-01-10 15:47:30