Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sha256

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sha256

Compute SHA256 of bytes or strings.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50K
decreased by-8.03%
Maintainers
3
Weekly downloads
 
Created
Source

sha256

JavaScript component to compute the SHA256 of strings or bytes.

Install

Node.js/Browserify

npm install --save sha256

Note: when Node.js is detected, the Node Crypto component is used instead of re-implementing the SHA256 hash logic.

Component

component install cryptocoinjs/sha256

Bower

bower install sha256

Script

<script src="/path/to/sha256.js"></script>

Usage

There are two methods, one for computing the hash of the input, and one for double-hashing it:

sha256('hello');   // "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
sha256.x2('hello'); // "d7914fe546b684688bb95f4f888a92dfc680603a75f23eb823658031fff766d9"

Input is either an array of bytes or a string. String are always interpreted as binary data; if you have a hex-encoded string of data to parse, first convert it to a binary string or array of bytes.

Output by default is a hexadecimal-encoded string. Other options are an array of bytes, or a binary-encoded string:

sha256('hello');   // "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824" <= Hex-encoded; default
sha256('hello', { asBytes: true }); // [44,242,77,186,95,176,163,14,38,232,59,42,197,185,226,158,27,22,30,92,31,167,66,94,115,4,51,98,147,139,152,36] <= Array of bytes
sha256('hello', { asString: true }); // ",òMº_°£&è;*Źâž\§B^s3b“‹˜$" <= Binary-encoded string

Test

Unit tests are written in Mocha. To run the test suite, checkout the git repository, and from within the base folder run:

$ npm install --dev
$ ./node_modules/mocha/bin/mocha

Credits

Most of the code from CryptoJS https://code.google.com/p/crypto-js/

License

(MIT License)

Copyright 2013, JP Richardson jprichardson@gmail.com

Keywords

FAQs

Package last updated on 02 Jan 2014

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