gpt4 book ai didi

encryption - 如何在 Node.js 中使用公钥加密数据?

转载 作者:IT老高 更新时间:2023-10-28 23:15:58 24 4
gpt4 key购买 nike

crypto 中,我只看到 Signer/Verifier 用于进行数字签名和使用对称 key 加密的 Cipher/Decipher。

如何使用公钥加密数据?

最佳答案

正如官方 nodejs api 文档中所述: crypto.publicEncrypt(key, buffer)

Encrypts the content of buffer with key and returns a new Buffer with encrypted content. The returned data can be decrypted using the corresponding private key, for example using crypto.privateDecrypt().

If key is not a KeyObject, this function behaves as if key had beenpassed to crypto.createPublicKey(). If it is an object, the paddingproperty can be passed. Otherwise, this function usesRSA_PKCS1_OAEP_PADDING.

Because RSA public keys can be derived from private keys, a privatekey may be passed instead of a public key.

所以答案是:

var encrypted = crypto.publicEncrypt(publicKey, buffer);

关于encryption - 如何在 Node.js 中使用公钥加密数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7779191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com