问题 如何使用NodeJS中的公钥加密数据?


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

如何使用公钥加密数据?


2128
2017-10-15 16:45


起源



答案:


对于那些在谷歌搜索时遇到这个问题的人,另一个问题已经得到了回答 使用node.js中的公钥加密数据 效果很好。


8
2018-05-15 01:31





你可能对我感兴趣 NaCl结合。从其API:

// encrypt and sign
box(message, nonce, pubkey, privkey)
// decrypt and validate
unbox(box, nonce, pubkey, privkey)
// generates a new keypair, returns {private: <buffer>, public: <buffer>}
boxKeypair()
// lengths of nonces and public and private keys in bytes
// { nonce: x, pubkey: x, privkey: x }
lengths.box

2
2017-10-30 21:50



可能不再有用了: blog.chromium.org/2017/05/goodbye-pnacl-hello-webassembly.html - James Moore


答案:


对于那些在谷歌搜索时遇到这个问题的人,另一个问题已经得到了回答 使用node.js中的公钥加密数据 效果很好。


8
2018-05-15 01:31





你可能对我感兴趣 NaCl结合。从其API:

// encrypt and sign
box(message, nonce, pubkey, privkey)
// decrypt and validate
unbox(box, nonce, pubkey, privkey)
// generates a new keypair, returns {private: <buffer>, public: <buffer>}
boxKeypair()
// lengths of nonces and public and private keys in bytes
// { nonce: x, pubkey: x, privkey: x }
lengths.box

2
2017-10-30 21:50



可能不再有用了: blog.chromium.org/2017/05/goodbye-pnacl-hello-webassembly.html - James Moore


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


1
2018-03-19 10:03



感谢你的回答!虽然此代码可能提供问题的答案,但建议解释如何解决该问题。请更新答案,并解释此代码解决问题的方式和原因。 - Brett DeWoody
虽然您的代码段可能会解决问题,但您应该描述代码的用途(它如何解决问题)。此外,您可能想要检查 stackoverflow.com/help/how-to-answer - Ahmad F
虽然此代码段可能是解决方案, 包括解释 真的有助于提高你的帖子的质量。请记住,您将来会回答读者的问题,而这些人可能不知道您的代码建议的原因。 - yivi
不鼓励代码答案,因为他们没有为未来的读者提供太多信息,请为您所写的内容提供一些解释 - WhatsThePoint