A Node.js module for SHA-224
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.
Installation ⤓
npm install sha224
Usage
Importing
Import the module with
const SHA224 = ;
Available input types
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])
Buffer.from(arrayBuffer[, byteOffset[, length]])
Buffer.from(array)
Buffer.from(object[, offsetOrEncoding[, length]])
// SHA-224const SHA224 = ; // Input: "Green chá" in UTF-8.console;console;console;console;console;// All of them give `<Buffer 09 11 cc 3f 17 06 19 1a de 7b// cb ad fa 95 14 28 f6 09 ca a2 f1 76 e5 f7 e4 fe d6 e7>`. // Input: 0xC0FFEE.console;console;console;console;console;console;// All of them give `<Buffer 26 fb 46 cb 82 2b a8 2f 43 33// 9c b2 47 ec d1 11 77 07 83 f5 72 a9 b9 a5 cf 34 cd 46>`.
Working with the outputs
It returns a Buffer
, so you may do what you may do with a Buffer
.
// SHA-224const SHA224 = ; const nyanbuffer = ;console;// <Buffer e9 2b e7 21 c9 22 10 0b c8 81 65 2a 63// 11 c4 f9 29 03 76 68 05 e1 7f 1b d2 af 31 34> console;// "e92be721c922100bc881652a6311c4f92903766805e17f1bd2af3134" console;// "6SvnIckiEAvIgWUqYxHE+SkDdmgF4X8b0q8xNA==" console;// [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;// true
Warning ⚠️
Hashing passwords
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)
Hashing huge data
This module is not appropriate for hashing huge binary data, such as that of a 1 GB file.
Specification reference 📖
Request for Comments #6234(RFC 6234) ‘US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)’
- §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.
Federal Information Processing Standards Publication 180-4(FIPS PUB 180-4) ‘Secure Hash Standard (SHS)’
- §5.3.6: SHA-512/t.
published by National Institute of Standards and Technology (NIST) in August 2015.
License 📜
This Javascript module has been licensed under the MIT license.