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');
sha256.x2('hello');
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');
sha256('hello', { asBytes: true });
sha256('hello', { asString: true });
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