首页 > 解决方案 > JS前端加密公私钥

问题描述

我正在尝试使用 javascript 使用一些公钥-私钥方法加密前端中的一些字符串,其中只有后端可以使用私钥解密,这可能吗?我怎样才能实现它?

我不介意它是否具有真正的基本加密,只要它具有公钥和私钥

// This is an EXAMPLE of what I want:

let message = encrypt("hello word!","public_key");
let decrypt_message = decrypt(message, "public_key");

/* the decrypt() method should throws error cuz the user shouldn't be able to
 * decrypt his own message with the public_key
 */

另请注意,我已经在使用 HTTPS,但拥有额外的安全性并不会伤害任何人 :)

提前谢谢你♥</p>

标签: javascriptencryption

解决方案


CryptoJS / crypto-js 和 JSEncrypt / jsencrypt 是您可以使用的库。

您需要加密您的数据加密密钥以发送到后端,然后您可以在后端使用私钥和加密密钥对其进行解码。


推荐阅读