阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js crypto.randomFill

      Node.js crypto.randomFill(buffer[, offset][, size], callback)

      新增于: v7.10.0

      • buffer < Buffer> |必须被支持.
      • offset < number> Defaults to 0.
      • size < number> Defaults to buffer.length - offset.
      • callback < Function> function(err, buf) {}.

      This function is similar to crypto.randomBytes() but requires the first argument to be a Buffer that will be filled. It also requires that a callback is passed in.

      If the callback function is not provided, an error will be thrown.

      const buf = Buffer.alloc(10);
      crypto.randomFill(buf, (err, buf) => {
        if (err) throw err;
        console.log(buf.toString('hex'));
      });
      
      crypto.randomFill(buf, 5, (err, buf) => {
        if (err) throw err;
        console.log(buf.toString('hex'));
      });
      
      // The above is equivalent to the following:
      crypto.randomFill(buf, 5, 5, (err, buf) => {
        if (err) throw err;
        console.log(buf.toString('hex'));
      });
      

      Note that this API uses libuv’s threadpool, which can have surprising and negative performance implications for some applications, see the UV_THREADPOOL_SIZE documentation for more information.

      Note: The asynchronous version of crypto.randomFill() is carried out in a single threadpool request. To minimize threadpool task length variation, partition large randomFill requests when doing so as part of fulfilling a client request.


      更多内容请参考:Node.js crypto 加密,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录