How to use the pseudoRandomBytes function from crypto

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

17
18
19
20
21
22
23
24
25
26


function comparePasswords(a, b) {
  // make shure booth buffers have same length and make time comparision attacks to
  // guess pw length harder by calculation fixed length hmacs first
  let key = crypto.pseudoRandomBytes(32);
  let bufA = crypto.createHmac('sha256', key).update(a).digest();
  let bufB = crypto.createHmac('sha256', key).update(b).digest();

  let ret = true;
fork icon445
star icon0
watch icon67

34
35
36
37
38
39
40
41
42
43
/**
 * Convienence method to run the functions typically used to build a process.
 */
build(){
    fs.ensureDirSync(this.gameDir)
    const tempNativePath = path.join(os.tmpdir(), ConfigManager.getTempNativeFolder(), crypto.pseudoRandomBytes(16).toString('hex'))
    process.throwDeprecation = true
    this.setupLiteLoader()
    logger.info('Using liteloader:', this.usingLiteLoader)
    const modObj = this.resolveModConfiguration(ConfigManager.getModConfiguration(this.server.getID()).mods, this.server.getModules())
fork icon0
star icon1
watch icon0

61
62
63
64
65
66
67
68
69
70

// make sure that we do not fail because we ran out of entropy
try {
  rnd = crypto.randomBytes(howMany);
} catch (e) {
  rnd = crypto.pseudoRandomBytes(howMany);
}

for (var i = 0; i < howMany; i++) {
  value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
fork icon0
star icon0
watch icon1

+ 3 other calls in file

37
38
39
40
41
42
43
44
45
46
pbkdf2Sync: { enumerable: true, value: bind(crypto, crypto.pbkdf2Sync) },
privateDecrypt: { enumerable: true, value: bind(crypto, crypto.privateDecrypt) },
privateEncrypt: { enumerable: true, value: bind(crypto, crypto.privateEncrypt) },
prng: { enumerable: true, value: bind(crypto, crypto.prng) },
pseudoRandomBytes: { enumerable: true, value: promisify(crypto, crypto.pseudoRandomBytes, 1) },
pseudoRandomBytesSync: { enumerable: true, value: crypto.pseudoRandomBytes.bind(crypto) },
publicDecrypt: { enumerable: true, value: bind(crypto, crypto.publicDecrypt) },
publicEncrypt: { enumerable: true, value: bind(crypto, crypto.publicEncrypt) },
randomBytes: { enumerable: true, value: promisify(crypto, crypto.randomBytes, 1) },
randomBytesSync: { enumerable: true, value: crypto.randomBytes.bind(crypto) },
fork icon0
star icon0
watch icon0

6
7
8
9
10
11
12
13
14
15
16
const uploadDir = '.' + faviconUploadDir;
const faviconUpload = app => {
    var storage = multer.diskStorage({
        destination: uploadDir,
        filename: function (req, file, cb) {
            crypto.pseudoRandomBytes(16, function (err, raw) {console.log('errerr',err)
                if (err) return cb(err);


                let ext;

fork icon0
star icon0
watch icon0

50
51
52
53
54
55
56
57
58
59
60
      throw new Error('randomBytes');
    });
  }


  function three() {
    crypto.pseudoRandomBytes(4, function() {
      throw new Error('pseudoRandomBytes');
    });
  }
});
fork icon0
star icon0
watch icon0

11
12
13
14
15
16
17
18
    // without enough entropy).
    //
    // However, due to a change in Node 0.10.27+, pseudoRandomBytes is now the
    // same as randomBytes, and may in fact block in situations where
    // insufficent entropy is available.
    return crypto.pseudoRandomBytes(4).toString('hex')
  }
}
fork icon0
star icon0
watch icon0

214
215
216
217
218
219
220
221
222
223
    util.packUInt32LE(options.protocolVersion),
    networkServices,
    util.packInt64LE(Date.now() / 1000 | 0),
    emptyNetAddress, //addr_recv, can be empty
    emptyNetAddress, //addr_from, can be empty
    crypto.pseudoRandomBytes(8), //nonce, random unique ID
    userAgent,
    blockStartHeight,
    relayTransactions
]);
fork icon0
star icon0
watch icon0