使用 aws-crypto 散列密码

hash password using aws-crypto

我想知道如何使用 aws-crypto (aws-encryption-sdk-javascript) 散列密码。 我已经使用 @aws-crypto/client-node 库使用 KMS 进行了一些对称加密。

import { KmsKeyringNode, encrypt, decrypt } from '@aws-crypto/client-node';

const keyring = new KmsKeyringNode({
  generatorKeyId: "keyid"
});

const { result } = await encrypt(keyring, cleartext);
const { plaintext } = await decrypt(keyring, result);

console.log(plaintext);

我使用这种方法加密密码的问题是,我仍然能够解密密码。我不需要此功能,因为我只想加密密码并使用相同的加密方式检查其他字符串是否与那些加密的字符串匹配。

如何使用 aws-crypto 和 KMS 做到这一点?

aws-crypto 客户端库主要针对 encryption/decryption 用例。如果我了解您的用例,我认为常规的加盐密码哈希是合适的。

bcrypt package is quite popular and has a good interface. Or there are solutions that don't require third-party packages, for example using the native Node.js crypto module.