@cryptography/sha256

中文文档
0.2.0发布于 2020/03/27GPL-3.0-or-laterTypeScriptESM + CJS零依赖近 30 天下载 4544

High-performance synchronous SHA-256 implementation for JavaScript

原始使用文档
文档目录8 节
  1. Features
  2. Setup
  3. Usage
  4. Benchmarks
  5. 2x faster at desktop browsers (benchmarked with Macbook Pro…
  6. 4x faster at mobile browsers (benchmarked with iPhone 6S 13…
  7. Try yourself
  8. Contributing

@cryptography/sha256

Bundlephobia Coverage Travis CI

High-performance synchronous SHA-256 implementation for JavaScript. Optimized for browsers.

Features

  • Blazing fast
  • Ultra lightweight
  • ECMAScript 3-6
  • Typed
  • Tested`

Setup

Package is available through npm and yarn

npm install @cryptography/sha256
yarn add @cryptography/sha256

Usage

This package is optimized for small byte inputs (<10kb).

Also, it is highly recommended to run CPU-intensive tasks in a Web Worker.

import sha256 from '@cryptography/sha256'

// as Uint32Array([0xa8d627d9, 0x3f518e90, 0x96b6f40e, 0x36d27b76, 0x60fa26d3, 0x18ef1adc, 0x43da750e, 0x49ebe4be])
const array = sha256('Hello World!') 

// as hex-string: "a8d627d93f518e9096b6f40e36d27b7660fa26d318ef1adc43da750e49ebe4be"
const hex = sha256('Hello World!', 'hex')

// as binary string: "ÄïükYo‡UH½LÛ,Zß\nNÆêE©¡‡`M¢"
const raw = sha256('Hello World!', 'binary')

// UInt32Array as input
const buf = new Uint32Array([0xa8d627d9, 0x3f518e90, 0x96b6f40e, 0x36d27b76, 0x60fa26d3, 0x18ef1adc, 0x43da750e, 0x49ebe4be]);
sha256(buf)

For hashing large files or other data chuncks use stream() to create a hashing stream.

sha256.stream().update('Hello World!').digest();

Benchmarks

Faster than forge, sjcl and WebCrypto API in sequence mode.

2x faster at desktop browsers (benchmarked with Macbook Pro 2016)

Macbook 2016 perfromance

4x faster at mobile browsers (benchmarked with iPhone 6S 13.2)

iPhone 6S perfromance

Try yourself

Contributing

Contributions are welcome! Contribution guidelines will be published soon.

版本与发布记录

@cryptography/sha256 共发布 6 个版本,首次发布于 2019/12/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.0latest2020/03/276 年前
0.1.42019/12/116 年前
0.1.32019/12/116 年前
0.1.22019/12/046 年前
0.1.12019/12/046 年前
0.1.02019/12/046 年前

关于 @cryptography/sha256 的常见问题

@cryptography/sha256 是什么?

High-performance synchronous SHA-256 implementation for JavaScript

如何安装 @cryptography/sha256?

在项目目录运行 npm install @cryptography/sha256,或使用 pnpm add / yarn add / bun add。

@cryptography/sha256 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cryptography/sha256 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cryptography/sha256 可以商用吗?

@cryptography/sha256 使用 GPL-3.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以 GPL-3.0 兼容许可开源,并附带专利与反锁定条款。仅内部使用不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@cryptography/sha256 的下载量有多少?

根据 npm 官方下载统计,@cryptography/sha256 在 2026/10/11 – 2026/11/09 这 30 天内被下载 4,544 次,日均约 151 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cryptography/sha256 还在维护吗?

最新版本 0.2.0 发布于 2020/03/27(6 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/12/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。