@aws-crypto/client-node

中文文档
5.0.2发布于 2026/07/24Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 385.1万

这个 客户端节点 模块包括所有您需要使用带有Node.js的JavaScript的AWS加密SDK模块.

中文使用文档
文档目录6 节
  1. 安装
  2. 使用情况
  3. 测试
  4. 兼容性考虑
  5. RSA 选项
  6. 许可证

为节点.js的 JavaScript 客户端加密 AWS SDK

@aws-crypto/客户端-节点

这个 客户端节点 模块包括您需要使用 AWS 加密 SDK 的所有模块 JavaScript 有节点.js.

  • 解密节点
  • 加密节点
  • 千米键环-节点
  • 材料管理-节点
  • 缓冲-材料-管理-节点
  • 原始键盘节点
  • 生- rsa- keyring- 节点

对于显示如何创建密钥环和加密及解密数据的模块的代码示例,请安装 示例节点 模块.

安装

要安装此模块, 请使用 npm 软件包管理器 。 安装帮助请参见 https://www.npmjs.com/get-npm (英语)。 。 。 .

npm install @aws-crypto/client-node

使用情况

详细代码示例 告诉你如何使用这些模块 创建密钥环 并加密和解密数据, 安装 示例节点 模块.


/* Start by constructing a keyring. We'll create a KMS keyring.
 * Specify an AWS Key Management Service (AWS KMS) customer master key (CMK) to be the
 * generator key in the keyring. This CMK generates a data key and encrypts it. 
 * To use the keyring to encrypt data, you need kms:GenerateDataKey permission 
 * on this CMK. To decrypt, you need kms:Decrypt permission. 
 */
const generatorKeyId = 'arn:aws:kms:us-west-2:658956600833:alias/EncryptDecrypt'

/* You can specify additional CMKs for the keyring. The data key that the generator key
 * creates is also encrypted by the additional CMKs you specify. To encrypt data, 
 *  you need kms:Encrypt permission on this CMK. To decrypt, you need kms:Decrypt permission.
 */ 
const keyIds = ['arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f']

/* Create the KMS keyring */
const keyring = new KmsKeyringNode({ generatorKeyId, keyIds })

/* Set an encryption context For more information: 
 * https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
 */
const context = {
    stage: 'demo',
    purpose: 'simple demonstration app',
    origin: 'us-west-2'
  }
 
/* Create a string to encrypt */
const cleartext = 'asdf'

/* Encrypt the string using the keyring and the encryption context 
 * the Encryption SDK returns an "encrypted message" (`result`) that includes the ciphertext
 * the encryption context, and the encrypted data keys.
 */ 
const { result } = await encrypt(keyring, cleartext, { encryptionContext: context })

/* Decrypt the result using the same keyring */
const { plaintext, messageHeader } = await decrypt(keyring, result)

/* Get the encryption context */
const { encryptionContext } = messageHeader

/* Verify that all values in the original encryption context are in the 
 * current one. (The Encryption SDK adds extra values for signing.) 
 */
 Object
    .entries(context)
    .forEach(([key, value]) => {
      if (encryptionContext[key] !== value) throw new Error('Encryption Context does not match expected values')
    })

/* If the encryption context is verified, return the plaintext. */

测试

npm test

兼容性考虑

RSA 选项

Node.js Crypto不支持由其他执行AWS加密SDK支持的所有 RSA 密钥包装选项

支持的配置为:

  • OAEP 有SHA1, MGF1 有SHA1
  • PKCS1v15 车次

许可证

此 SDK 分布于 Apache 许可证,2.0版本, (中文(简体) ), 更多信息见LICENSE.txt和Notice.txt.

版本与发布记录

@aws-crypto/client-node 共发布 38 个版本,首次发布于 2019/06/22;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.0.2latest2026/07/243 个月前
4.2.42026/07/243 个月前
5.0.02026/04/246 个月前
4.2.22026/03/078 个月前
4.2.12025/04/111.6 年前
4.2.02025/02/281.7 年前

关于 @aws-crypto/client-node 的常见问题

@aws-crypto/client-node 是什么?

这个 客户端节点 模块包括所有您需要使用带有Node.js的JavaScript的AWS加密SDK模块.

如何安装 @aws-crypto/client-node?

在项目目录运行 npm install @aws-crypto/client-node,或使用 pnpm add / yarn add / bun add。

@aws-crypto/client-node 支持 TypeScript 吗?

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

@aws-crypto/client-node 支持 ESM 还是 CommonJS?

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

@aws-crypto/client-node 可以商用吗?

@aws-crypto/client-node 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aws-crypto/client-node 的下载量有多少?

根据 npm 官方下载统计,@aws-crypto/client-node 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,851,258 次,日均约 128,375 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aws-crypto/client-node 还在维护吗?

最新版本 5.0.2 发布于 2026/07/24(3 个月前);至今共发布 38 个版本,其中过去 12 个月发布了 4 个;首次发布于 2019/06/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。