Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • digest/digest.c
  • digest/lib/digest.rb

Class/Module Index [+]



This module stands as a base class for digest implementation classes.

Public Class Methods

base64digest(str, *args) click to toggle source

Returns the base64 encoded hash value of a given string. The return value is properly padded with ‘=’ and contains no line feeds.

               # File digest/lib/digest.rb, line 35
def self.base64digest(str, *args)
  [digest(str, *args)].pack('m0')
Digest::Class.digest(string, *parameters) → hash_string click to toggle source

Returns the hash value of a given string. This is equivalent to Digest::Instance#new.digest(string), where extra parameters, if any, are passed through to the constructor and the string is passed to digest().

               static VALUE
rb_digest_class_s_digest(int argc, VALUE *argv, VALUE klass)
    VALUE str;
    volatile VALUE obj;

    if (argc < 1) {
        rb_raise(rb_eArgError, "no data given");

    str = *argv++;


    obj = rb_obj_alloc(klass);
    rb_obj_call_init(obj, argc, argv);

    return rb_funcall(obj, id_digest, 1, str);
file(name) click to toggle source

creates a digest object and reads a given file, name.

p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
# => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
               # File digest/lib/digest.rb, line 28
def self.file(name)
Digest::Class.hexdigest(string[, ...]) → hash_string click to toggle source

Returns the hex-encoded hash value of a given string. This is almost equivalent to Digest.hexencode(Digest::Class.new(*parameters).digest(string)).

               static VALUE
rb_digest_class_s_hexdigest(int argc, VALUE *argv, VALUE klass)
    return hexencode_str_new(rb_funcall2(klass, id_digest, argc, argv));

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.