10 examples of 'crypto.getrandomvalues' in JavaScript

Every line of 'crypto.getrandomvalues' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
55static generateRandom(length = 128, wordArray = false) {
56 let random = CryptoJS.lib.WordArray.random(length/8);
57 return (wordArray) ? random : random.toString();
58}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

12getRandomValues (buffer) {
13 return crypto.randomFillSync(buffer)
14}
25function getRandomByte() {
26 keySchedule_i = (keySchedule_i + 1) % 256;
27 keySchedule_j = (keySchedule_j + keySchedule[keySchedule_i]) % 256;
28
29 var t = keySchedule[keySchedule_i];
30 keySchedule[keySchedule_i] = keySchedule[keySchedule_j];
31 keySchedule[keySchedule_j] = t;
32
33 return keySchedule[(keySchedule[keySchedule_i] + keySchedule[keySchedule_j]) % 256];
34}
422function UTIL_getRandom(a) {
423 var tmp = new Array(a);
424 var rnd = new Uint8Array(a);
425 window.crypto.getRandomValues(rnd);
426 for (var i = 0; i < a; ++i) tmp[i] = rnd[i] & 255;
427 return tmp;
428}
25function getRandomBytes(count) {
26 var output = [];
27 for (var i = 0; i < count; i++)
28 output.push(Math.floor(Math.random() * 255));
29
30 return output;
31}
49return function getRandomValues(buffer: Uint8Array): void {
50 return crypto.getRandomValues(buffer);
51}
16function random(l) {
17 var ary = []
18 while(l --) ary.push(crypto.randomBytes(1024))
19 return ary
20}
23function getRandomByte() {
24 if (typeof window !== "undefined") { // Browser
25 if (typeof window.crypto !== "undefined") { // Supported
26 let array = new Uint8Array(1);
27 window.crypto.getRandomValues(array);
28 return array[0];
29 }
30 else { // fallback
31 return Math.floor(Math.random() * 256);
32 }
33 }
34 else { // NodeJS
35 return module.require("crypto").randomBytes(1)[0];
36 }
37}
42function rng() {
43 // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
44 let rnds8 = new Uint8Array(16);
45
46 return CRYPTO.getRandomValues(rnds8);
47}
10function randomBytes(size) {
11 var bytes = new Array(size);
12 var r;
13
14 for (var i = 0, r; i < size; i++) {
15 if ((i & 0x03) == 0) r = Math.random() * 0x100000000;
16 bytes[i] = (r >>> ((i & 0x03) << 3)) & 0xff;
17 }
18
19 return bytes;
20}

Related snippets