1.0.0 • Published 8 years ago

blake2js v1.0.0

Weekly downloads
9
License
MIT
Repository
github
Last release
8 years ago

Blake2-JS

Straightforward bindings for the Blake2 hashing library.

License Travis-CI Coveralls npm

Package

About Blake2

BLAKE2 is a cryptographic hash function faster than MD5, SHA-1, SHA-2, and SHA-3, yet is at least as secure as the latest standard SHA-3. - official website

This modules relies on the official C implementation of the library and requires a c++11 capable compiler. It is compatible with node 0.10.x and greater (I've not tried with earlier versions but there shouldn't be major problems).

Installation

$ npm install --save-dev blake2js

Usage

var blake2 = require('blake2js'); // or let/const
import blake2 from 'blake2js';  // in ES6+ syntax

Method: hash

hash(algorithm, data, options, encoding) <Buffer> | <String>

  • algorithm <String>
    Algorithm to use, can either be "blake2s", "blake2sp", "blake2b" or "blake2bp".
  • data <Object> | <Buffer> | <String>
    The data can be passed as an object whose "raw" property contains a string/Buffer to be hashed and an "encoding" property which indicates the encoding of the raw field (ignored if buffer). Otherwise you can directly pass a Buffer or a string (utf-8 encoding is assumed).
  • options <Object>
    Hash options (see below).
  • encoding
    This determines the output format for the hash; if none is specified a Buffer is returned.

Method: createHash

createHash(algorithm, options) <Hash>

  • algorithm <String>
    Blake2 algorithm (see above for valid values).
  • options <Object>
    • outlen <Number>
      Output's length in bytes. Must be a positive number smaller or equal to the maximum outbut bytes (32 for blake2s(p) and 64 for blake2b(p)).
    • key <Buffer> | <String>
      If specified this will produced a keyed hash using the specified key.
    • encoding <String>
      This is the key's encoding, if not specified utf-8 is assumed.

Class: Hash

constructor(options)

  • options <Object>
    Hash options (see above).

update(data[, encoding]) <Hash>

  • data <Buffer> | <String>
    Data to update the hash with.
  • encoding <String> If data is a string, the encoding will be used to decode it. If none is specified then utf-8 is assumed.
  • returns: the instance itself (useful for chaining).

digest(encoding) <Buffer> | <String>

  • Completes the hash and returns the result. By default returns a Buffer, if an argument is passed it will be used as encoding to stringify it. (digest(encoding) === digest().toString(encoding))

An important thing is that Hash instances can be used as transform streams, exactly as documented on node's crypto api.