Skip to content
Tiny hashing module that uses the native crypto API in Node.js and the browser
Branch: master
Clone or download
Latest commit fc519ea May 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Init Mar 7, 2018
.gitattributes Meta tweaks Nov 8, 2018
.gitignore Init Mar 7, 2018
.npmrc Init Mar 7, 2018
.travis.yml Move hashing to worker thread (#7) May 3, 2019
browser.js Use `globalThis` ponyfill Nov 8, 2018
index.d.ts Meta tweaks May 3, 2019
index.js Move hashing to worker thread (#7) May 3, 2019
index.test-d.ts Add TypeScript definition (#5) Apr 9, 2019
license Init Mar 7, 2018
package.json 1.2.0 May 3, 2019
readme.md Move hashing to worker thread (#7) May 3, 2019
test-browser.js Init Mar 7, 2018
test.js Move hashing to worker thread (#7) May 3, 2019
thread.js Move hashing to worker thread (#7) May 3, 2019

readme.md

crypto-hash Build Status

Tiny hashing module that uses the native crypto API in Node.js and the browser

Useful when you want the same hashing API in all environments. My cat calls it isomorphic.

In Node.js it uses require('crypto'), while in the browser it uses window.crypto.

The browser version is only ~300 bytes minified & gzipped.

Install

$ npm install crypto-hash

Usage

const {sha256} = require('crypto-hash');

(async () => {
	console.log(await sha256('🦄'));
	//=> '5df82936cbf0864be4b7ba801bee392457fde9e4'
})();

API

sha1(input, [options])

sha256(input, [options])

sha384(input, [options])

sha512(input, [options])

Returns a Promise<string> with a hex-encoded hash.

In Node.js 12 or later, the operation is executed using worker_threads. A thread is lazily spawned on the first operation and lives until the end of the program execution. It's unrefed, so it won't keep the process alive.

SHA-1 is insecure and should not be used for anything sensitive.

input

Type: string ArrayBuffer ArrayBufferView

options

Type: Object

outputFormat

Type: string
Values: hex buffer
Default: hex

Setting this to buffer makes it return an ArrayBuffer instead of a string.

Related

  • hasha - Hashing in Node.js made simple

License

MIT © Sindre Sorhus

You can’t perform that action at this time.