sha256-uint8array
Fast SHA-256 digest hash based on Uint8Array, pure JavaScript.
SYNOPSIS
const createHash = require("sha256-uint8array").createHash;
const text = "";
const hex = createHash().update(text).digest("hex");
const data = new Uint8Array(0);
const hash = createHash().update(data).digest();
The interface is a subset of Node.js's crypto module.
See TypeScript declaration
sha256-uint8array.d.ts
for detail.
BENCHMARK
Node.js's native crypto
module run faster than others on Node.js.
sha256-uint8array
runs well both on Node.js and browsers with its smaller footprint.
module | version | node.js V14 | Chrome 87 | Safari 14 | minified | backend | note |
---|
crypto | - | 99ms 👍 | - | - | - | OpenSSL | 👍 on node.js |
sha256-uint8array | 0.8.0 | 261ms | 474ms 👍 | 270ms 👍 | 3KB 👍 | Uint8Array | 👍 on browsers |
crypto-js | 4.0.0 | 835ms | 928ms | 957ms | 108KB | Uint8Array | crypto-js/sha256.js |
jssha | 3.2.0 | 852ms | 937ms | 950ms | 10KB | Uint8Array | jssha/dist/sha256.js |
hash.js | 1.1.7 | 654ms | 631ms | 1,641ms | 7KB | Array | hash.js/lib/hash/sha/1.js |
sha.js | 2.4.11 | 351ms | 731ms | 3,617ms | 27KB | Buffer | sha.js/sha256.js |
create-hash | 1.2.0 | 404ms | 788ms | 3,640ms | 97KB | Buffer | create-hash/browser.js |
jshashes | 1.0.8 | 1,532ms | 2,335ms | 1,128ms | 23KB | Array | jshashes/hashes.js |
The benchmark result above is tested on macOS 10.15.7 Intel Core i7 3.2GHz. You could run the benchmark as below.
git clone https://github.com/kawanet/sha256-uint8array.git
npm install
npm run build
REPEAT=10000 ./node_modules/.bin/mocha test/99.benchmark.js
make -C browser test
BROWSER
<script src="https://cdn.jsdelivr.net/npm/sha256-uint8array/dist/sha256-uint8array.min.js"></script>
<script>
const text = "";
const hex = SHA256.createHash().update(text).digest("hex");
const data = new Uint8Array(0);
const hash = SHA256.createHash().update(data).digest();
</script>
LINKS
MIT LICENSE
Copyright (c) 2020-2021 Yusuke Kawasaki
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.