A Javascript implementation of SHA-224 for Node.js.
npm install sha224 This Javascript module implements the SHA-224 cryptographic hash function designed by _the United States National Security Agency (NSA)_. This module is a wrapper of the sha2 module.
```
npm install sha224
Import the module with
`javascript`
const SHA224 = require("sha224");
It basically takes a Buffer. Everything other than a Buffer as its input turns into a Buffer with Buffer.from() internally. Reading these would help you understand it:
- [Buffer.from(string[, encoding])](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_string_encoding)Buffer.from(arrayBuffer[, byteOffset[, length]])
- [](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length)Buffer.from(array)
- Buffer.from(object[, offsetOrEncoding[, length]])
- [](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_object_offsetorencoding_length)
`javascript
// SHA-224
const SHA224 = require("sha224");
// Input: "Green chá" in UTF-8.
console.log(SHA224("Green chá"));
console.log(SHA224("Green chá", "utf8"));
console.log(SHA224("477265656e206368c3A1", "hex"));
console.log(SHA224("R3JlZW4gY2jDoQ==", "base64"));
console.log(SHA224([
0x47, 0x72, 0x65, 0x65, 0x6E, 0x20, 0x63, 0x68, 0xC3, 0xA1
]));
// All of them give .
// Input: 0xC0FFEE.
console.log(SHA224(Buffer.from([0xC0, 0xFF, 0xEE])));
console.log(SHA224((new Uint8Array([0xC0, 0xFF, 0xEE])).buffer));
console.log(SHA224(
(new Uint8Array([0xC0, 0x01, 0xC0, 0xFF, 0xEE])).buffer,
2
));
console.log(SHA224("C0ffee", "hex"));
console.log(SHA224("wP/u", "base64"));
console.log(SHA224([0xC0, 0xFF, 0xEE]));
// All of them give .`
It returns a Buffer, so you may do what you may do with a Buffer.
`javascript
// SHA-224
const SHA224 = require("sha224");
const nyanbuffer = SHA224(
░░░░░░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░░░░░
░░░░░░█░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░█░░░░░
░░░░░░█░█░▀░░░░░▀░░▀░░░░█░█░░░░░
░░░░░░█░█░░░░░░░░▄▀▀▄░▀░█░█▄▀▀▄░
█▀▀█▄░█░█░░▀░░░░░█░░░▀▄▄█▄▀░░░█░
▀▄▄░▀██░█▄░▀░░░▄▄▀░░░░░░░░░░░░▀▄
░░▀█▄▄█░█░░░░▄░░█░░░▄█░░░▄░▄█░░█
░░░░░▀█░▀▄▀░░░░░█░██░▄░░▄░░▄░███
░░░░░▄█▄░░▀▀▀▀▀▀▀▀▄░░▀▀▀▀▀▀▀░▄▀░
░░░░█░░▄█▀█▀▀█▀▀▀▀▀▀█▀▀█▀█▀▀█░░░
░░░░▀▀▀▀░░▀▀▀░░░░░░░░▀▀▀░░▀▀░░░░);
console.log(nyanbuffer);
//
console.log(nyanbuffer.toString("hex"));
// "e92be721c922100bc881652a6311c4f92903766805e17f1bd2af3134"
console.log(nyanbuffer.toString("base64"));
// "6SvnIckiEAvIgWUqYxHE+SkDdmgF4X8b0q8xNA=="
console.log(Array.from(nyanbuffer));
// [233, 43, 231, 33, 201, 34, 16, 11, 200, 129, 101, 42, 99, 17,
// 196, 249, 41, 3, 118, 104, 5, 225, 127, 27, 210, 175, 49, 52]
console.log(nyanbuffer.equals(nyanbuffer));
// true
``
Making a hash of a password with one of the algorithms of the SHA-2 family and keeping it, is not recommended.
For that purpose, use slow hash functions which are slow by design such as PBKDF2, bcrypt, and scrypt, instead.
- How to securely hash passwords? (_Information security Stack Exchange_)
- Salted Password Hashing - Doing it Right (_CrackStation_)
- How To Safely Store A Password (_Coda Hale_)
This module is not appropriate for hashing huge binary data, such as that of a 1 GB file.
- §1: Overview of Contents.
- §2: Notation for Bit Strings and Integers.
- §3: Operations on Words.
- §4: Message Padding and Parsing.
- §5: Functions and Constants Used.
- §6: Computing the Message Digest.
written by _Donald E. Eastlake 3rd_, and _Tony Hansen_ in May 2011.
- §5.3.6: SHA-512/t.
published by _National Institute of Standards and Technology (NIST)_ in August 2015.
This Javascript module has been licensed under the MIT license.