How to use the randomFill function from crypto

Find comprehensive JavaScript crypto.randomFill code examples handpicked from public code repositorys.

79
80
81
82
83
84
85
86
87
88
  };

  args.push(cb);

  try {
    crypto.randomFill(...args);
  } catch (e) {
    reject(e);
  }
});
fork icon42
star icon0
watch icon2

812
813
814
815
816
817
818
819
820
821
  data = JSON.parse(data);
} catch (e) {
  return void resp_func('ERR_INVALID_DATA');
}
// Generate a (likely unique) random ID to reference this profile by
crypto.randomFill(Buffer.alloc(9), (err, buf) => {
  if (err) {
    throw err;
  }
  let uid = buf.toString('base64');
fork icon9
star icon34
watch icon0

101
102
103
104
105
106
107
108
109
110
111
}


{
  const buf = Buffer.alloc(10);
  const before = buf.toString('hex');
  crypto.randomFill(buf, common.mustSucceed((buf) => {
    const after = buf.toString('hex');
    assert.notStrictEqual(before, after);
  }));
}
fork icon0
star icon0
watch icon0

+ 35 other calls in file

-3
-2
-1
} else {
  module.exports = require('./browser')
}
fork icon0
star icon0
watch icon0

99
100
101
102
103
104
105
106
107
108
109
}


{
  const buf = Buffer.alloc(10);
  const before = buf.toString('hex');
  crypto.randomFill(buf, common.mustCall((err, buf) => {
    assert.ifError(err);
    const after = buf.toString('hex');
    assert.notStrictEqual(before, after);
  }));
fork icon0
star icon0
watch icon0

+ 11 other calls in file

18
19
20
21
22
23
24
25
26
27
28
29
30


const startCrypto = () => {
  crypto.scrypt(password, "salt", 24, (err, key) => {
    if (err) throw err;


    crypto.randomFill(new Uint8Array(16), (err, iv) => {
      if (err) throw err;


      const cipher = crypto.createCipheriv(algorithm, key, iv);

fork icon0
star icon0
watch icon0