小编Alf*_*nso的帖子

使用 AWS 加密库和 NestJS 时出现“EC2 元数据 roleName 请求返回错误”

我正在尝试在 NestJS 应用程序中使用 aws 加密 sdk,下一个代码源显示了实现。

import { Controller, Get } from '@nestjs/common';
import {KmsKeyringNode, encrypt} from '@aws-crypto/client-node'


@Controller('encryption')
export class EncryptionController {
  // constructor() {}
  @Get()
  async crypt() {
    const generatorKeyId = "generatior key";
    const masterKeyId = "master key id";
    const keyring = new KmsKeyringNode({keyIds:[masterKeyId], generatorKeyId: generatorKeyId});
    const plainText = "My passwords for senstive data";
    const context = {
      accountId: "100",
      purpose: "youtube demo",
      country: "Sri Lanka"
    };
    const { result } = await encrypt(keyring, plainText, { encryptionContext: context …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services node.js amazon-kms nestjs

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

amazon-kms ×1

amazon-web-services ×1

nestjs ×1

node.js ×1