js-sha256
A simple SHA-256 / SHA-224 hash function for JavaScript supports UTF-8 encoding.
Demo
SHA256 Online
SHA224 Online
Download
Compress
Uncompress
Installation
You can also install js-sha256 by using Bower.
bower install js-sha256
For node.js, you can use this command to install:
npm install js-sha256
Usage
You could use like this:
sha256('Message to hash');
sha224('Message to hash');
var hash = sha256.create();
hash.update('Message to hash');
hash.hex();
var hash2 = sha256.update('Message to hash');
hash2.update('Message2 to hash');
hash2.array();
sha256.hmac('key', 'Message to hash');
sha224.hmac('key', 'Message to hash');
var hash = sha256.hmac.create('key');
hash.update('Message to hash');
hash.hex();
var hash2 = sha256.hmac.update('key', 'Message to hash');
hash2.update('Message2 to hash');
hash2.array();
Node.js
If you use node.js, you should require the module first:
var sha256 = require('js-sha256');
or
var sha256 = require('js-sha256').sha256;
var sha224 = require('js-sha256').sha224;
or
const { sha256, sha224 } = require('js-sha256');
TypeScript
If you use TypeScript, you can import like this:
import { sha256, sha224 } from 'js-sha256';
RequireJS
It supports AMD:
require(['your/path/sha256.js'], function(sha256) {
});
Example
sha256('');
sha256('The quick brown fox jumps over the lazy dog');
sha256('The quick brown fox jumps over the lazy dog.');
sha224('');
sha224('The quick brown fox jumps over the lazy dog');
sha224('The quick brown fox jumps over the lazy dog.');
sha256('中文');
sha224('中文');
sha256([]);
sha256(new Uint8Array([211, 212]));
sha256('');
sha256.hex('');
sha256.array('');
sha256.digest('');
sha256.arrayBuffer('');
License
The project is released under the MIT license.
Contact
The project's website is located at https://github.com/emn178/js-sha256
Author: Chen, Yi-Cyuan (emn178@gmail.com)