MCPcopy
hub / github.com/cyao2q/files / cryptoSecureRandomInt

Function cryptoSecureRandomInt

js/crypto-js.js:62–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60 * As Math.random() is cryptographically not safe to use
61 */
62 var cryptoSecureRandomInt = function () {
63 if (crypto) {
64 // Use getRandomValues method (Browser)
65 if (typeof crypto.getRandomValues === 'function') {
66 try {
67 return crypto.getRandomValues(new Uint32Array(1))[0];
68 } catch (err) {}
69 }
70
71 // Use randomBytes method (NodeJS)
72 if (typeof crypto.randomBytes === 'function') {
73 try {
74 return crypto.randomBytes(4).readInt32LE();
75 } catch (err) {}
76 }
77 }
78
79 throw new Error('Native crypto module could not be used to get secure random number.');
80 };
81
82 /*
83 * Local polyfill of Object.create

Callers 1

crypto-js.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…