js-sha3


A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.
Notice
- Sha3 methods has been renamed to keccak since v0.2.0. It means that sha3 methods of v0.1.x are equal to keccak methods of v0.2.x and later.
buffer
method is deprecated. This maybe confuse with Buffer in node.js. Please use arrayBuffer
instead.
Demo
SHA3-512 Online
SHA3-384 Online
SHA3-256 Online
SHA3-224 Online
Keccak-512 Online
Keccak-384 Online
Keccak-256 Online
Keccak-224 Online
Shake128 Online
Shake256 Online
Download
Compress
Uncompress
Installation
You can also install js-sha3 by using Bower.
bower install js-sha3
For node.js, you can use this command to install:
npm install js-sha3
Usage
You could use like this:
sha3_512('Message to hash');
sha3_384('Message to hash');
sha3_256('Message to hash');
sha3_224('Message to hash');
keccak512('Message to hash');
keccak384('Message to hash');
keccak256('Message to hash');
keccak224('Message to hash');
shake128('Message to hash', 256);
shake256('Message to hash', 512);
cshake128('Message to hash', 256, 'function name', 'customization');
cshake256('Message to hash', 512, 'function name', 'customization');
kmac128('key', 'Message to hash', 256, 'customization');
kmac256('key', 'Message to hash', 512, 'customization');
var buffer = keccak224.buffer('Message to hash');
var buffer = keccak224.array('Message to hash');
sha3_512.update('Message ').update('to ').update('hash').hex();
shake128.update('Message ', 256).update('to ').update('hash').hex();
var hash = sha3_512.create();
hash.update('...');
hash.update('...');
hash.hex();
var hash = shake128.create(256);
hash.update('...');
hash.update('...');
hash.hex();
var hash = cshake128.create(256, 'function name', 'customization');
var hash = kmac128.create('key', 256, 'customization');
If you use node.js, you should require the module first:
sha3_512 = require('js-sha3').sha3_512;
sha3_384 = require('js-sha3').sha3_384;
sha3_256 = require('js-sha3').sha3_256;
sha3_224 = require('js-sha3').sha3_224;
keccak512 = require('js-sha3').keccak512;
keccak384 = require('js-sha3').keccak384;
keccak256 = require('js-sha3').keccak256;
keccak224 = require('js-sha3').keccak224;
shake128 = require('js-sha3').shake128;
shake256 = require('js-sha3').shake256;
cshake128 = require('js-sha3').cshake128;
cshake256 = require('js-sha3').cshake256;
kmac128 = require('js-sha3').kmac128;
kmac256 = require('js-sha3').kmac256;
If you use TypeScript, you can import like this:
import { sha3_512 } from 'js-sha3';
Example
Code
sha3_512('');
sha3_512('The quick brown fox jumps over the lazy dog');
sha3_512('The quick brown fox jumps over the lazy dog.');
sha3_384('');
sha3_384('The quick brown fox jumps over the lazy dog');
sha3_384('The quick brown fox jumps over the lazy dog.');
sha3_256('');
sha3_256('The quick brown fox jumps over the lazy dog');
sha3_256('The quick brown fox jumps over the lazy dog.');
sha3_224('');
sha3_224('The quick brown fox jumps over the lazy dog');
sha3_224('The quick brown fox jumps over the lazy dog.');
keccak512('');
keccak512('The quick brown fox jumps over the lazy dog');
keccak512('The quick brown fox jumps over the lazy dog.');
keccak384('');
keccak384('The quick brown fox jumps over the lazy dog');
keccak384('The quick brown fox jumps over the lazy dog.');
keccak256('');
keccak256('The quick brown fox jumps over the lazy dog');
keccak256('The quick brown fox jumps over the lazy dog.');
keccak224('');
keccak224('The quick brown fox jumps over the lazy dog');
keccak224('The quick brown fox jumps over the lazy dog.');
shake128('', 256);
shake256('', 512);
It also supports UTF-8 encoding:
Code
sha3_512('中文');
sha3_384('中文');
sha3_256('中文');
sha3_224('中文');
keccak512('中文');
keccak384('中文');
keccak256('中文');
keccak224('中文');
It also supports byte Array
, Uint8Array
, ArrayBuffer
input:
Code
sha3_512([]);
sha3_512(new Uint8Array([]));
Benchmark
UTF8
ASCII
License
The project is released under the MIT license.
Contact
The project's website is located at https://github.com/emn178/js-sha3
Author: Chen, Yi-Cyuan (emn178@gmail.com)