crypto.randomFillSync(buffer[, offset][, size])
历史
版本 | 变化 |
---|---|
v9.0.0 |
|
v7.10.0、v6.13.0 | 添加于:v7.10.0、v6.13.0 |
参数
buffer
<ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> 必须提供。提供的buffer
的大小不得大于2**31 - 1
。offset
<number> 默认:0
size
<number> 默认:buffer.length - offset
。size
不得大于2**31 - 1
。- 返回: <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> 作为
buffer
参数传递的对象。
的同步版本。crypto.randomFill()
import { Buffer } from 'node:buffer'; const { randomFillSync } = await import('node:crypto'); const buf = Buffer.alloc(10); console.log(randomFillSync(buf).toString('hex')); randomFillSync(buf, 5); console.log(buf.toString('hex')); // The above is equivalent to the following: randomFillSync(buf, 5, 5); console.log(buf.toString('hex'));
const { randomFillSync } = require('node:crypto'); const { Buffer } = require('node:buffer'); const buf = Buffer.alloc(10); console.log(randomFillSync(buf).toString('hex')); randomFillSync(buf, 5); console.log(buf.toString('hex')); // The above is equivalent to the following: randomFillSync(buf, 5, 5); console.log(buf.toString('hex'));
任何 ArrayBuffer
、 TypedArray
或 DataView
实例都可以作为 buffer
传递。
import { Buffer } from 'node:buffer'; const { randomFillSync } = await import('node:crypto'); const a = new Uint32Array(10); console.log(Buffer.from(randomFillSync(a).buffer, a.byteOffset, a.byteLength).toString('hex')); const b = new DataView(new ArrayBuffer(10)); console.log(Buffer.from(randomFillSync(b).buffer, b.byteOffset, b.byteLength).toString('hex')); const c = new ArrayBuffer(10); console.log(Buffer.from(randomFillSync(c)).toString('hex'));
const { randomFillSync } = require('node:crypto'); const { Buffer } = require('node:buffer'); const a = new Uint32Array(10); console.log(Buffer.from(randomFillSync(a).buffer, a.byteOffset, a.byteLength).toString('hex')); const b = new DataView(new ArrayBuffer(10)); console.log(Buffer.from(randomFillSync(b).buffer, b.byteOffset, b.byteLength).toString('hex')); const c = new ArrayBuffer(10); console.log(Buffer.from(randomFillSync(c)).toString('hex'));
相关用法
- Node.js crypto.randomFillSync()用法及代码示例
- Node.js crypto.randomFill()用法及代码示例
- Node.js crypto.randomFill(buffer[, offset][, size], callback)用法及代码示例
- Node.js crypto.randomInt([min, ]max[, callback])用法及代码示例
- Node.js crypto.randomBytes()用法及代码示例
- Node.js crypto.randomInt()用法及代码示例
- Node.js crypto.randomUUID()用法及代码示例
- Node.js crypto.randomBytes(size[, callback])用法及代码示例
- Node.js crypto.createHmac()用法及代码示例
- Node.js crypto.constants用法及代码示例
- Node.js crypto.publicEncrypt()用法及代码示例
- Node.js crypto.publicDecrypt()用法及代码示例
- Node.js crypto.pbkdf2Sync(password, salt, iterations, keylen, digest)用法及代码示例
- Node.js crypto.createHash()用法及代码示例
- Node.js crypto.hkdfSync()用法及代码示例
- Node.js crypto.checkPrime()用法及代码示例
- Node.js crypto.sign()用法及代码示例
- Node.js crypto.webcrypto用法及代码示例
- Node.js crypto.generateKeyPairSync(type, options)用法及代码示例
- Node.js crypto.createCipheriv()用法及代码示例
- Node.js crypto.scrypt(password, salt, keylen[, options], callback)用法及代码示例
- Node.js crypto.createVerify()用法及代码示例
- Node.js crypto.getCurves()用法及代码示例
- Node.js crypto.generateKeyPair()用法及代码示例
- Node.js crypto.createDiffieHellman()用法及代码示例
注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 crypto.randomFillSync(buffer[, offset][, size])。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。