A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/phusion/node-sha3 below:

GitHub - phusion/node-sha3: SHA3 for JavaScript

A pure JavaScript implementation of the Keccak family of cryptographic hashing algorithms, most notably including Keccak and SHA3.

💡 Legacy Note: In previous versions of this library, the SHA3Hash object provided a Keccak hash, not what we currently know as a SHA-3 hash. For backwards-compatibility, this object is still exported. However, users are encouraged to switch to using the SHA3 or Keccak objects instead, which provide the SHA-3 and Keccak hashing algorithms, respectively.

Via npm:

Via yarn:

You can use this library from Node.js, from web browsers, and/or using ES6 imports.

// Standard FIPS 202 SHA-3 implementation
const { SHA3 } = require('sha3');

// The Keccak hash function is also available
const { Keccak } = require('sha3');

// The SHAKE extendable output function (XOF) is also available
const { SHAKE } = require('sha3');
// Standard FIPS 202 SHA-3 implementation
import { SHA3 } from 'sha3';

// The Keccak hash function is also available
import { Keccak } from 'sha3';

// The SHAKE extendable output function (XOF) is also available
import { SHAKE } from 'sha3';

FIPS-compatible interfaces for the following algorithms:

💡 Legacy Note: Savvy inspectors may notice that SHA3Hash is also provided. Prior to v2.0.0, this library only implemented an early version of the SHA3 algorithm. Since then, SHA3 has diverged from Keccak and is using a different padding scheme, but for compatibility, this alias is sticking around for a bit longer.

Generating a SHA3-512 hash
import { SHA3 } from 'sha3';

const hash = new SHA3(512);

hash.update('foo');
hash.digest('hex');
Generating a Keccak-256 hash
import { Keccak } from 'sha3';

const hash = new Keccak(256);

hash.update('foo');
hash.digest('hex');
Generating a SHAKE128 hash with 2048 bytes
import { SHAKE } from 'sha3';

const hash = new SHAKE(128);

hash.update('foo');
hash.digest({ buffer: Buffer.alloc(2048), format: 'hex' });

All hash implementations provided by this library conform to the following API specification.

The constructor for each hash (e.g: Keccak, SHA3), expects the following parameters:

// Construct a new Keccak hash of size 256
const hash = new Keccak(256);
#update(data, [encoding='utf8'])

Updates the hash content with the given data. Returns the hash object itself.

💡 See Buffers and Character Encodings for a list of allowed encodings.

const hash = new Keccak(256);

hash.update('hello');

hash.update('we can also chain these').update('together');
#digest([encoding='binary'])

Digests the hash and returns the result. After calling this function, the hash may continue to receive input.

If an encoding is provided and is a value other than 'binary', then this function returns a string. Otherwise, it returns a Buffer.

💡 See Buffers and Character Encodings for a list of allowed encodings.

const hash = new Keccak(256);

hash.update('hello');

hash.digest('hex');
// => hash of 'hello' as a hex-encoded string

Digests the hash and returns the result. After calling this function, the hash may continue to receive input.

Options include:

If a format is provided and is a value other than 'binary', then this function returns a string. Otherwise, it returns a Buffer.

const hash = new Keccak(256);

hash.update('hello');

hash.digest({ buffer: Buffer.alloc(32), format: 'hex' });
// => hash of 'hello' as a hex-encoded string

Resets a hash to its initial state.

const hash = new Keccak(256);

hash.update('hello');
hash.digest();
// => hash of 'hello'

hash.reset();

hash.update('world');
hash.digest();
// => hash of 'world'

Run yarn test for the full test suite.

Cryptographic hashes provide integrity, but do not provide authenticity or confidentiality. Hash functions are one part of the cryptographic ecosystem, alongside other primitives like ciphers and MACs. If considering this library for the purpose of protecting passwords, you may actually be looking for a key derivation function, which can provide much better security guarantees for this use case.

The following resources were invaluable to this implementation and deserve special thanks for work well done:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4