You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
626 B
21 lines
626 B
var SecureRandom = require('../common/SecureRandom');
|
|
|
|
SecureRandom.getRandomBuffer = function(size) {
|
|
if (!window.crypto && !window.msCrypto)
|
|
throw new Error('window.crypto not available');
|
|
|
|
if (window.crypto && window.crypto.getRandomValues)
|
|
var crypto = window.crypto;
|
|
else if (window.msCrypto && window.msCrypto.getRandomValues) //internet explorer
|
|
var crypto = window.msCrypto;
|
|
else
|
|
throw new Error('window.crypto.getRandomValues not available');
|
|
|
|
var bbuf = new Uint8Array(size);
|
|
crypto.getRandomValues(bbuf);
|
|
var buf = new Buffer(bbuf);
|
|
|
|
return buf;
|
|
};
|
|
|
|
module.exports = (SecureRandom);
|
|
|