VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-crypto-randomfillsync-method/

⇱ Node.js crypto.randomFillSync() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js crypto.randomFillSync() Method

Last Updated : 28 Apr, 2025

The crypto.randomFillSync() method is an inbuilt application programming interface of crypto module which is used to return the object passed as buffer argument.
Syntax: 
 

crypto.randomFillSync( buffer, offset, size )


Parameters: This method accept three parameters as mentioned above and described below: 
 

  • buffer This parameter holds Buffer, TypedArray, or DataView type of data.
  • offset: It is a number whose default value is 0.
  • size: It is a number whose default value is (buffer.length - offset).


Return Value: It returns Buffer, TypedArray, or DataView type of data.
Below example illustrate the use of crypto.randomFillSync() method in Node.js:
Example 1: 
 

Output: 
 

+~`Ld#%KT&6VF1e
K/7gTBXCFISh30dPoE5o
K/7gTO7iUG+h30dPoE5o


Here, the last two values are same.
Example 2: 
 

Output: 
 

BQrDFc8=

EM4;)N+.qY, o-kp:b:C.

479eb4d9175221


Here, any TypedArray, or DataView instance is passed as buffer.
Reference: https://nodejs.org/api/crypto.html#crypto_crypto_randomfillsync_buffer_offset_size
 

Comment

Explore