js-sha512
A simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.
Notice
- v0.8.0+ will throw an error if try to update hash after finalize.
Demo
SHA512 Online
SHA384 Online
SHA512/256 Online
SHA512/224 Online
Download
Compress
Uncompress
Installation
You can also install js-sha512 by using Bower.
bower install js-sha512
For node.js, you can use this command to install:
npm install js-sha512
Usage
Node.js
If you use node.js, you should require the module first:
const { sha512, sha384, sha512_256, sha512_224 } = require('js-sha512');
TypeScript
If you use TypeScript, you can import like this:
import { sha512, sha384, sha512_256, sha512_224 } from 'js-sha512';
RequireJS
It supports AMD:
require(['your/path/sha512.js'], function(jsSha512) {
const { sha512, sha384, sha512_256, sha512_224 } = jsSha512;
});
Classic Browser
If you use browser script directly, functions will be global:
sha512('Message to hash');
sha384('Message to hash');
sha512_256('Message to hash');
sha512_224('Message to hash');
Example
You could use like this:
sha512('Message to hash');
sha384('Message to hash');
sha512_256('Message to hash');
sha512_224('Message to hash');
var arrayBuffer = sha512.arrayBuffer('Message to hash');
var bytes = sha512.digest('Message to hash');
var bytes = sha512.array('Message to hash');
var hash = sha512.update('Message to hash');
hash.update('Message2 to hash');
hash.hex();
var hash = sha512.create();
hash.update('Message to hash');
hash.hex();
var hash = sha512.update('Message to hash');
var hash2 = hash.clone();
hash2.hex();
hash.update('Message2 to hash');
hash.hex();
sha512.hmac('key', 'Message to hash');
sha384.hmac('key', 'Message to hash');
var hash = sha512.hmac.create('key');
hash.update('Message to hash');
hash.hex();
var hash2 = sha512.hmac.update('key', 'Message to hash');
hash2.update('Message2 to hash');
hash2.array();
sha512('');
sha512('The quick brown fox jumps over the lazy dog');
sha512('The quick brown fox jumps over the lazy dog.');
sha384('');
sha384('The quick brown fox jumps over the lazy dog');
sha384('The quick brown fox jumps over the lazy dog.');
sha512_256('');
sha512_256('The quick brown fox jumps over the lazy dog');
sha512_256('The quick brown fox jumps over the lazy dog.');
sha512_224('');
sha512_224('The quick brown fox jumps over the lazy dog');
sha512_224('The quick brown fox jumps over the lazy dog.');
sha512('中文');
sha384('中文');
sha512_256('中文');
sha512_224('中文');
sha512('');
sha512.hex('');
sha512.array('');
sha512.digest('');
sha512.arrayBuffer('');
sha512.hmac.hex('key', 'Message to hash');
sha512.hmac.array('key', 'Message to hash');
License
The project is released under the MIT license.
Contact
The project's website is located at https://github.com/emn178/js-sha512
Author: Chen, Yi-Cyuan (emn178@gmail.com)