Generating random numbers properly depends on the platform. The new getRandomBuffer method does the right thing on the right platform. It will sometimes fail due to insufficient entropy. The getPseudoRandomBuffer class is also provided that will never fail, but it is not cryptographically secure and should not be used for keys.
11 lines
271 B
JavaScript
11 lines
271 B
JavaScript
var imports = require('soop');
|
|
var crypto = imports.crypto || require('crypto');
|
|
|
|
var SecureRandom = require('../common/SecureRandom');
|
|
|
|
SecureRandom.getRandomBuffer = function(size) {
|
|
return crypto.randomBytes(size);
|
|
}
|
|
|
|
module.exports = require('soop')(SecureRandom);
|