I use node.js 6.9.5.
I want to use crypto module but whatever I use it gives me the error:
secure random number generation not supported by this browser
How to make this work?
(and I would understand it doesn't let me generate pair of keys or something that needs random numbers, but I get the same error on some functions that don't need random numbers)
Wrong repo, see https://github.com/crypto-browserify/randombytes/issues/6.
@bnoordhuis This module is not maintained by you?
crypto-browserify is implementation for browser. I use node.js module.
@croraf No. The built-in crypto module is but you're not using that, you're using the browserified version.
@bnoordhuis No, I use built-in crypto module.
Based on your error message, it doesn't seem you are. If you think we're incorrect in this assumption, please post a code sample of what you're trying to do. It's hard to help without having more info.
As far as I can tell, you're probably using https://github.com/rzcoder/node-rsa which is not maintained by anyone here and any questions should be directed to that project's issues.
For example:
var keypair = require('keypair');
var pair = keypair();
var crypto = require("crypto");
crypto.publicEncrypt(pair.public, new Buffer("message"));
Guys I tried every library, node-rsa was first one, giving me the same error as node's crypto. Not one seems to work one way or another. :D But this is node's crypto.
Seems like your issue is with keypair, not node.
No. keypair runs fine, and produces the keys. I tried other ways also, issue arises with crypto (crypto.publicEncrypt in this case).
I use webpack, and this piece is probably erroneous:
var crypto = global.crypto || global.msCrypto
if (crypto && crypto.getRandomValues) {
module.exports = randomBytes
} else {
module.exports = oldBrowser
}
(globalprobably comes from webpack)
This part: crypto.getRandomValues is not implemented in crypto on my node software would be my guess.
You know what. I ran it directly, without bundling it first and it runs fine.
webpack isn't designed to bundle serverside code...
Hmmm. True. I copied my old frontend code to reuse some. OK, I think this will solve the issue. THANKS!
Most helpful comment
No. keypair runs fine, and produces the keys. I tried other ways also, issue arises with crypto
(crypto.publicEncryptin this case).I use webpack, and this piece is probably erroneous:
(
globalprobably comes from webpack)This part:
crypto.getRandomValuesis not implemented incryptoon mynodesoftware would be my guess.