javascript - 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>
解决方案
CryptoJS / crypto-js 和 JSEncrypt / jsencrypt 是您可以使用的库。
您需要加密您的数据加密密钥以发送到后端,然后您可以在后端使用私钥和加密密钥对其进行解码。
推荐阅读
- python - 如何正确地将组权限分配给 Django CMS 中的特定页面?
- neo4j - apoc 触发器使用 apoc.es.put 将新创建的 neo4j 节点发送到 elasticsearch
- c - 数组,isdigit 函数,while 循环
- java - 在 Spring MVC 中找不到类 @ 无法捕获 @Controller
- vue.js - Vuejs动态添加类
- c# - ASP.NET Core MVC - 在运行时绑定到模型
- java - 加权投票通常应该提高 KNN 分类器的准确性吗?
- python-3.x - 如何合并标记相同的两列内容?
- python - 将“复杂数组”拆分为“实数”和“虚数”数组的快捷方式
- python - 使用 pandas 将父表与子表组合/合并