![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@stablelib/sha256
Advanced tools
@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.
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'));
The 'crypto' module is a built-in Node.js module that provides cryptographic functionality, including the SHA-256 hash function. It is widely used and well-maintained, but it is not as lightweight or specialized as @stablelib/sha256.
The 'js-sha256' package is a JavaScript implementation of the SHA-256 hash function. It is lightweight and easy to use, similar to @stablelib/sha256, but it may not be as optimized for performance and security.
The 'sha.js' package is a JavaScript implementation of the SHA family of hash functions, including SHA-256. It is well-maintained and widely used, but it is not as specialized as @stablelib/sha256.
FAQs
SHA-256 cryptographic hash function
The npm package @stablelib/sha256 receives a total of 305,686 weekly downloads. As such, @stablelib/sha256 popularity was classified as popular.
We found that @stablelib/sha256 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.