10 examples of 'crypto randombytes' in JavaScript

Every line of 'crypto randombytes' 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
11export function bytes(length: number): Buffer
12{
13 return randomBytes(length);
14}
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

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}
3export function random(): string {
4 return randomBytes(16).toString('hex');
5}
49function random () {
50 return crypto.randomBytes(20).toString('hex')
51}
108randomBytes(length: number): Promise<ArrayBuffer> {
109 return this.bwCrypto.randomBytes(length);
110}
55static generateRandom(length = 128, wordArray = false) {
56 let random = CryptoJS.lib.WordArray.random(length/8);
57 return (wordArray) ? random : random.toString();
58}
16function random(l) {
17 var ary = []
18 while(l --) ary.push(crypto.randomBytes(1024))
19 return ary
20}
22exports.randomBytes = function randomBytes(size) {
23 const data = new Uint8Array(size);
24 crypto.getRandomValues(data);
25 return Buffer.from(data.buffer);
26};
190function randomBytes (n) {
191 var buf = bufferAlloc(n)
192 sodium.randombytes_buf(buf)
193 return buf
194}
29function random(qty) {
30 return crypto.randomBytes(qty);
31}

Related snippets