@ecies/ciphers

中文文档
0.2.6发布于 2026/04/01MITTypeScriptCommonJS零依赖构建来源已验证近 30 天下载 5803.2万

Node/Pure JavaScript symmetric ciphers adapter

原始使用文档
文档目录3 节
  1. Quick start
  2. Supported ciphers
  3. Known limitations

@ecies/ciphers

License NPM Package NPM Downloads Install size CI Codecov

Node/Pure JavaScript symmetric ciphers adapter.

If native implementations are available on some platforms (e.g. node, deno, bun), it'll use node:crypto for efficiency.

Otherwise (e.g. browser, react native), it'll use @noble/ciphers for compatibility.

aeschacha
Nodenode:crypto ⚡node:crypto ⚡
Bunnode:crypto ⚡@noble/ciphers
Denonode:crypto ⚡node:crypto ⚡
Browser@noble/ciphers@noble/ciphers
React Native@noble/ciphers@noble/ciphers

[!NOTE] You may need to polyfill crypto.getRandomValues for React Native.

There are some limitations, see Known limitations below.

This library is tree-shakeable, unused code will be excluded by bundlers.

Check the example folder for more usages.

Quick start

// example/quick-start.js
import { aes256gcm } from "@ecies/ciphers/aes";
import { randomBytes } from "@noble/ciphers/webcrypto";

const TEXT = "hello world🌍!";
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const msg = encoder.encode(TEXT);

const key = randomBytes();
const nonce = randomBytes(16);
const cipher = aes256gcm(key, nonce);
console.log("decrypted:", decoder.decode(cipher.decrypt(cipher.encrypt(msg))));

The API follows @noble/ciphers's API for ease of use, you can check their examples as well.

Supported ciphers

  • aes-256-gcm
    • Both 16 bytes and 12 bytes nonce are supported.
  • aes-256-cbc
    • Only for legacy applications. You should use xchacha20-poly1305 or aes-256-gcm as possible.
    • Nonce is always 16 bytes.
  • chacha20-poly1305
    • Nonce is always 12 bytes.
  • xchacha20-poly1305
    • Nonce is always 24 bytes.

If key is fixed and nonce is less than 16 bytes, avoid randomly generated nonce.

Known limitations

  • xchacha20-poly1305 is implemented with pure JS hchacha20 function and node:crypto's chacha20-poly1305 on node/deno.
  • Currently (Apr 2026), node:crypto's chacha20-poly1305 is not supported on bun, @noble/ciphers's implementation is used instead. From deno 2.7.10, node:crypto's chacha20-poly1305 is supported. Please upgrade deno to use native implementation for better performance.
  • Some old versions of deno did not support indirect conditional exports. For example, if a library uses @ecies/ciphers, client code of that library might fall back to the node:crypto implementation and would not work properly, specifically aes-256-gcm and chacha20-poly1305. If you found such a problem, upgrade deno and run with --conditions deno (>=2.4.0) or --unstable-node-conditions deno(>=2.3.6,<2.4.0).

版本与发布记录

@ecies/ciphers 共发布 8 个版本,首次发布于 2024/10/12;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.6latest2026/04/017 个月前
0.2.52025/11/041 年前
0.2.42025/07/051.4 年前
0.2.32025/03/061.7 年前
0.2.22024/11/292 年前
0.2.12024/10/312 年前

关于 @ecies/ciphers 的常见问题

@ecies/ciphers 是什么?

Node/Pure JavaScript symmetric ciphers adapter

如何安装 @ecies/ciphers?

在项目目录运行 npm install @ecies/ciphers,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@noble/ciphers(^1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ecies/ciphers 支持 TypeScript 吗?

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

@ecies/ciphers 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@ecies/ciphers 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ecies/ciphers 可以商用吗?

@ecies/ciphers 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ecies/ciphers 的下载量有多少?

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

@ecies/ciphers 还在维护吗?

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