# sha256

> Compute SHA256 of bytes or strings.

Latest version **0.2.0** (published 2015-03-18) · 0 weekly downloads

## Install

```sh
npm install sha256
pnpm add sha256
yarn add sha256
bun add sha256
```

## Health

**Score 18/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2015-03-18 |
| First published | 2013-11-21 |
| Weekly downloads | 0 |
| TypeScript types | separate (@types/sha256) |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 48 |
| Maintainers | vbuterin, midnightlightning, sidazhang, jprichardson |
| Keywords | string, strings, sha256, bytes, cryptography |

## Links

- npm: https://www.npmjs.com/package/sha256
- Repository: https://github.com/cryptocoinjs/sha256
- Issues: https://github.com/cryptocoinjs/sha256/issues
- npm.io page: https://npm.io/package/sha256

## Dependencies (2)

- [convert-hex](https://npm.io/package/convert-hex.md) ~0.1.0
- [convert-string](https://npm.io/package/convert-string.md) ~0.1.0

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2015-03-18
- 0.1.1 — 2014-01-02
- 0.1.0 — 2013-11-21

## README

# sha256

JavaScript component to compute the SHA256 of strings or bytes.

## DEPRECATION NOTICE

This library is deprecated. If you think it's important to maintain this library, please submit an issue and the case will be consider or the repo / ownership will be transferred to you. Viable alternatives:

1. Use Browserify
2. https://www.npmjs.com/package/sha.js (used by Browserify)
3. https://github.com/indutny/hash.js


## Install

### Node.js/Browserify

    npm install --save sha256

Note: when Node.js is detected, the Node [`Crypto`](http://nodejs.org/api/crypto.html) component is used instead of re-implementing the SHA256 hash logic.



## Usage

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

```js
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:

```js
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](http://visionmedia.github.io/mocha/). To run the test suite, checkout the git repository, and from within the base folder run:

```sh
$ npm install --dev
$ npm test
```

# Credits

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

# License

(MIT License)

Copyright 2013, JP Richardson  <jprichardson@gmail.com>

---
_Source: https://npm.io/package/sha256 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
