【发布时间】:2016-03-14 20:30:26
【问题描述】:
我正在 node.js 中寻找 RSA 加密的方法,我想处理大数字,所以我使用这个:https://github.com/eschnou/node-bignumber
我要做的只是加密,使用模数和指数。我不必进行解密。无论如何,我不断出错,但我不知道出了什么问题。谁能知道它出了什么问题?谢谢。
代码
require("node-bignumber");
var nvalue="ad6eb61316ff805e9c94667ab04aa45aa3203eef71ba8c12afb353a5c7f11657e43f5ce4483d4e6eca46af6b3bde4981499014730d3b233420bf3ecd3287a2768da8bd401f0abd7a5a137d700f0c9d0574ef7ba91328e9a6b055820d03c98d56943139075d";
var evalue="010001";
var encpw="";
var rsa = new RSAKey;
function encryptMessage() {
var message = "All your bases are belong to us.";
rsa.setPublic(evalue, nvalue);
encpw.value = rsa.encrypt(message);
console.log(encpw);
}
encryptMessage();
错误
ReferenceError: RSAKey is not defined
at Object.<anonymous> (c:\Users\win\Desktop\untitled\juntae.js:5:15)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
【问题讨论】:
-
JSBN的打包版本好像没有
RSAKey。你见过usage guidance吗?无论如何,如果你只是想做 RSA 加密,那么你真的应该使用内置的crypto 模块。 -
@ArtjomB。实际上 3 天前,我从弱基础 JavaScript 中跳入了 Nodejs。我认为 lib/rsa/rsa.js 上有 RSAKey 构造函数,但我不知道如何使用它。我从使用指南中将 RSAKey 更改为另一个,但我不知道...我很难理解,我不知道他们为什么在模数和指数上使用十六进制值。
-
@ArtjomB。我红了你推荐的nodejs api(加密模块),有一个用于RSA加密的功能。 crypto.publicEncrypt(public_key, buffer)。正确的?但是参数,我不明白。我认为公钥应该是一对。 (mod 和 exp) 但为什么参数只得到一个公钥?并且正在缓冲要加密的消息。正确的?所以我不知道该怎么办...我整天都在搜索这个简单的问题...
标签: node.js encryption rsa