You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

crypto-hash

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crypto-hash

Tiny hashing module that uses the native crypto API in Node.js and the browser

3.1.0
latest
Source
npmnpm
Version published
Weekly downloads
395K
8.23%
Maintainers
1
Weekly downloads
 
Created

What is crypto-hash?

The crypto-hash npm package is a simple and modern way to create cryptographic hashes in Node.js and the browser. It supports various hashing algorithms like SHA-256, SHA-384, and SHA-512, and provides a promise-based API for asynchronous operations.

What are crypto-hash'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 hash the string 'Hello, world!' and log the resulting hash.

const cryptoHash = require('crypto-hash');
(async () => {
  const hash = await cryptoHash.sha256('Hello, world!');
  console.log(hash);
})();

Hashing a file

This feature allows you to hash the contents of a file. The code sample demonstrates how to read a file into a buffer and then hash its contents using the SHA-256 algorithm.

const cryptoHash = require('crypto-hash');
const fs = require('fs');
(async () => {
  const fileBuffer = fs.readFileSync('path/to/file.txt');
  const hash = await cryptoHash.sha256(fileBuffer);
  console.log(hash);
})();

Using different algorithms

This feature allows you to use different hashing algorithms. The code sample demonstrates how to hash the same string using both the SHA-384 and SHA-512 algorithms.

const cryptoHash = require('crypto-hash');
(async () => {
  const sha384Hash = await cryptoHash.sha384('Hello, world!');
  const sha512Hash = await cryptoHash.sha512('Hello, world!');
  console.log('SHA-384:', sha384Hash);
  console.log('SHA-512:', sha512Hash);
})();

Other packages similar to crypto-hash

Keywords

crypto

FAQs

Package last updated on 29 Jul 2024

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.