阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js crypto.randomFillSync

      Node.js crypto.randomFillSync(buffer[, offset][, size]) 版本历史

      版本变更
      v9.0.0The buffer argument may be any TypedArray or DataView.
      v7.10.0, v6.13.0新增于: v7.10.0, v6.13.0
      • buffer < Buffer> ||Must be supplied.
      • offset < number> Default: 0
      • size < number> Default: buffer.length - offset
      • Returns: < Buffer> ||The object passed as buffer argument.

      Synchronous version of crypto.randomFill().

      const buf = Buffer.alloc(10);
      console.log(crypto.randomFillSync(buf).toString('hex'));
      
      crypto.randomFillSync(buf, 5);
      console.log(buf.toString('hex'));
      
      // The above is equivalent to the following:
      crypto.randomFillSync(buf, 5, 5);
      console.log(buf.toString('hex'));
      

      Any TypedArray or DataView instance may be passed as buffer.

      const a = new Uint32Array(10);
      console.log(Buffer.from(crypto.randomFillSync(a).buffer,
                              a.byteOffset, a.byteLength).toString('hex'));
      
      const b = new Float64Array(10);
      console.log(Buffer.from(crypto.randomFillSync(b).buffer,
                              b.byteOffset, b.byteLength).toString('hex'));
      
      const c = new DataView(new ArrayBuffer(10));
      console.log(Buffer.from(crypto.randomFillSync(c).buffer,
                              c.byteOffset, c.byteLength).toString('hex'));
      

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


      目录
      本文目录
      目录