hash

This module provides facilities for creating varios hashes over data.

Hash objects

All objects defined in this module inherit from a HashBase base class and thus have the same API.

class hash.HashBase()

Base class for all hash types. Currently the following classes are implemented:

  • MD5
  • SHA1
  • SHA256
  • SHA512
hash.HashBase.hash.HashBase.prototype.update(data)

Update the hash object with the given data. This function can be called multiple times in order to incrementally update the data being hashed.

Functions

hash.createHash(type)

Helper function to create hash objects. type must be (a string) one of:

  • md5
  • sha1
  • sha256
  • sha512

Examples

Using the helper function and chaining methods:

hash.createHash('sha1').update('abc').digest('hex');
// "a9993e364706816aba3e25717850c26c9cd0d89d"

Creating objects and calling methods individually:

var h1 = new hash.SHA1();
h1.update('abc');
h1.digest('hex');
// "a9993e364706816aba3e25717850c26c9cd0d89d"