【问题标题】:nodeJS ReferenceError : navigator is not defined.nodeJS ReferenceError:未定义导航器。
【发布时间】:2013-05-11 18:38:03
【问题描述】:

您好,我正在尝试让一些 Javascript 文件在 nodeJS 上运行,一切都设置得很好,但是这是我得到的错误:

C:\>node myServer.js

C:\myFunctionsCallTest.js:750
if( (j_lm && (navigator.appName == "Microsoft Internet Explorer")) || navigato
              ^
ReferenceError: navigator is not defined
    at Object.<anonymous> (C:\myFunctionsCallTest.js:750:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\myServer.js:1:79)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

C:\>

我使用的文件是:

myServer.js

var my_module = require("./myFunctionsCallTest.js");
console.log("RSA encrypted message :"+ my_module.Encrypt("myKey","myMessage"));

myFunctionsCallTest.js //This file contains some call of prototypes like : 
.....................................
RSAKey.prototype.setPublic = RSASetPublic;
RSAKey.prototype._short_encrypt = RSAEncrypt;
RSAKey.prototype.encrypt = RSAEncryptLong;
RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
..............................................

知道这个问题可能来自哪里吗? 谢谢。

【问题讨论】:

    标签: node.js rsa public-key-encryption


    【解决方案1】:

    您似乎正在使用 Tom Wu 的 BitInteger 和 RSA JavaScript 库。这个库是为在浏览器中使用而设计的,在 Node.js 中不能正常工作。

    幸运的是,有人已经完成了将这个库打包成 Node.js 兼容格式的工作;它在 GitHub 上的 https://github.com/eschnou/node-bignumber 上,可通过 npm 以包“bignumber”的形式获得,并附带一个不错的 example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 2021-04-24
      相关资源
      最近更新 更多