Socket
Socket
Sign inDemoInstall

@stablelib/sha256

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stablelib/sha256

SHA-256 cryptographic hash function


Version published
Weekly downloads
338K
increased by4.78%
Maintainers
1
Weekly downloads
 
Created

What is @stablelib/sha256?

@stablelib/sha256 is a JavaScript library that provides a secure and efficient implementation of the SHA-256 cryptographic hash function. It is part of the StableLib collection of cryptographic libraries, which are designed to be fast, secure, and easy to use.

What are @stablelib/sha256's main functionalities?

Hashing a string

This feature allows you to hash a string using the SHA-256 algorithm. The code sample demonstrates how to create a new hash instance, update it with a string, and then obtain the digest in hexadecimal format.

const { Hash } = require('@stablelib/sha256');
const hash = new Hash();
hash.update(Buffer.from('Hello, world!'));
const digest = hash.digest();
console.log(Buffer.from(digest).toString('hex'));

Hashing a file

This feature allows you to hash the contents of a file using the SHA-256 algorithm. The code sample demonstrates how to create a read stream for a file, update the hash with each chunk of data, and then obtain the digest in hexadecimal format once the stream ends.

const { Hash } = require('@stablelib/sha256');
const fs = require('fs');
const hash = new Hash();
const stream = fs.createReadStream('path/to/file');
stream.on('data', (chunk) => hash.update(chunk));
stream.on('end', () => {
  const digest = hash.digest();
  console.log(Buffer.from(digest).toString('hex'));
});

Hashing with incremental updates

This feature allows you to hash data incrementally using the SHA-256 algorithm. The code sample demonstrates how to create a new hash instance, update it with multiple chunks of data, and then obtain the digest in hexadecimal format.

const { Hash } = require('@stablelib/sha256');
const hash = new Hash();
hash.update(Buffer.from('Hello, '));
hash.update(Buffer.from('world!'));
const digest = hash.digest();
console.log(Buffer.from(digest).toString('hex'));

Other packages similar to @stablelib/sha256

FAQs

Package last updated on 21 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc