0.11.0 • Published 2 months ago

js-sha256 v0.11.0

Weekly downloads
337,274
License
MIT
Repository
github
Last release
2 months ago

js-sha256

Build Status Coverage Status CDNJS
NPM
A simple SHA-256 / SHA-224 hash function for JavaScript supports UTF-8 encoding.

Demo

SHA256 Online
SHA224 Online
SHA256 File Online
SHA225 File Online

Download

Compress
Uncompress

Installation

You can also install js-sha256 by using Bower.

bower install js-sha256

For node.js, you can use this command to install:

npm install js-sha256

Usage

You could use like this:

sha256('Message to hash');
sha224('Message to hash');

var hash = sha256.create();
hash.update('Message to hash');
hash.hex();

var hash2 = sha256.update('Message to hash');
hash2.update('Message2 to hash');
hash2.array();

// HMAC
sha256.hmac('key', 'Message to hash');
sha224.hmac('key', 'Message to hash');

var hash = sha256.hmac.create('key');
hash.update('Message to hash');
hash.hex();

var hash2 = sha256.hmac.update('key', 'Message to hash');
hash2.update('Message2 to hash');
hash2.array();

Node.js

If you use node.js, you should require the module first:

var sha256 = require('js-sha256');

or

var sha256 = require('js-sha256').sha256;
var sha224 = require('js-sha256').sha224;

or

const { sha256, sha224 } = require('js-sha256');

TypeScript

If you use TypeScript, you can import like this:

import { sha256, sha224 } from 'js-sha256';

RequireJS

It supports AMD:

require(['your/path/sha256.js'], function(sha256) {
// ...
});

Example

sha256(''); // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
sha256('The quick brown fox jumps over the lazy dog'); // d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592
sha256('The quick brown fox jumps over the lazy dog.'); // ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c
sha224(''); // d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f
sha224('The quick brown fox jumps over the lazy dog'); // 730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525
sha224('The quick brown fox jumps over the lazy dog.'); // 619cba8e8e05826e9b8c519c0a5c68f4fb653e8a3d8aa04bb2c8cd4c

// It also supports UTF-8 encoding
sha256('中文'); // 72726d8818f693066ceb69afa364218b692e62ea92b385782363780f47529c21
sha224('中文'); // dfbab71afdf54388af4d55f8bd3de8c9b15e0eb916bf9125f4a959d4

// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` input
sha256([]); // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
sha256(new Uint8Array([211, 212])); // 182889f925ae4e5cc37118ded6ed87f7bdc7cab5ec5e78faef2e50048999473f

// Different output
sha256(''); // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
sha256.hex(''); // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
sha256.array(''); // [227, 176, 196, 66, 152, 252, 28, 20, 154, 251, 244, 200, 153, 111, 185, 36, 39, 174, 65, 228, 100, 155, 147, 76, 164, 149, 153, 27, 120, 82, 184, 85]
sha256.digest(''); // [227, 176, 196, 66, 152, 252, 28, 20, 154, 251, 244, 200, 153, 111, 185, 36, 39, 174, 65, 228, 100, 155, 147, 76, 164, 149, 153, 27, 120, 82, 184, 85]
sha256.arrayBuffer(''); // ArrayBuffer

Benchmark

jsPerf Benchmark

License

The project is released under the MIT license.

Contact

The project's website is located at https://github.com/emn178/js-sha256
Author: Chen, Yi-Cyuan (emn178@gmail.com)

c8osdkangular@jdutchak/argosidmaster-archive-common@pai-tech/pai-vaultethers-pulsarhybrix-nodeinipaycredify-jsveriglifsign-signerresponsive-it-common@lianlian2019/blockchain_sdkgdevdirectpay-cardpaymentui-21e8components-21e8anatha-sdktyrtgfagsd-apicf-compencf-compen5skyweb-revisedhtdf_web3_ordinaryweb3_htdf@pano.video/panortc-activexpayper-widgetexplorer-mixins@global-vue/layout@kravc/expo-portal-agent@kravc/expo-portal-polyfills@kravc/portal@kravc/identity-request@aries-framework/core-testscrt-link-modulef95api@skylar745/3box@mc3-aether/aether@mc3-aether/identity-wallet@andrii-solokh/binance-connectoriota-poex-toolunstoppable-domainslee-resolutionaries-framework-testintezer-js-preldrn-sdkcv-app-payment-adyenbtc-address-validatorsid-npm-test3sid-npmtest-1sid-npmtest-2sid-test-create-npm@mazarine-sea/maz-keyring@getcheck/apicyberco-sc-common-modulesinterlinked-sdkyo-ui-new@soreduard/tyrecclesiafacebook-business-sdkjs-umbral@anstest/address-encoderreact-native-project-serum-anchorsymbol-sdk-twix@cmss-bfs/bview@kronosapiens/mirror@magnet.me/site-diffethernity-cloud-runnergdcxapicontrol1mrkreszunleash-serverfacebook-business-sdk-tsrn-keycloak-js@everything-registry/sub-chunk-1977gc-bwp-web-ui@d-protocol/d-lib@ubtools/commonmyathhhh2023mintservable-engine@servable/enginepush-web-widgetlighticlibwallet-mnzlifeid-didlifeid-did-jwtlingui-message-utils-patchl-dashboardlfs-apilitemessagellyyss-sdkhextronwebhifisdkgameshifive-vue-clihw_btchw_coinshydrotechybrixdkeycloak-js-simplekeycloak-js-ssrkeycloak-js-without-credentialskitargkeycloak-capacitor
0.11.0

2 months ago

0.10.0

7 months ago

0.10.1

7 months ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

10 years ago

0.1.0

10 years ago