npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sha224

v1.0.0

Published

A Javascript implementation of SHA-224 for Node.js.

Downloads

341

Readme

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 = require("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:

// 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 `<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.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 `<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-224
const SHA224 = require("sha224");

const nyanbuffer = SHA224(`
░░░░░░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░░░░░
░░░░░░█░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░█░░░░░
░░░░░░█░█░▀░░░░░▀░░▀░░░░█░█░░░░░
░░░░░░█░█░░░░░░░░▄▀▀▄░▀░█░█▄▀▀▄░
█▀▀█▄░█░█░░▀░░░░░█░░░▀▄▄█▄▀░░░█░
▀▄▄░▀██░█▄░▀░░░▄▄▀░░░░░░░░░░░░▀▄
░░▀█▄▄█░█░░░░▄░░█░░░▄█░░░▄░▄█░░█
░░░░░▀█░▀▄▀░░░░░█░██░▄░░▄░░▄░███
░░░░░▄█▄░░▀▀▀▀▀▀▀▀▄░░▀▀▀▀▀▀▀░▄▀░
░░░░█░░▄█▀█▀▀█▀▀▀▀▀▀█▀▀█▀█▀▀█░░░
░░░░▀▀▀▀░░▀▀▀░░░░░░░░▀▀▀░░▀▀░░░░
`);
console.log(nyanbuffer);
// <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.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

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.

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.