Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
126K
decreased by-33.12%
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

FAQs

Package last updated on 12 Aug 2020

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