Node.js crypto.pbkdf2Sync() Method Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The crypto.pbkdf2Sync() method gives a synchronous Password-Based Key Derivation Function 2 i.e, (PBKDF2) implementation. Moreover, a particular HMAC digest algorithm which is defined by digest is implemented to derive a key of the required byte length (keylen) from the stated password, salt, and iterations. Syntax: crypto.pbkdf2Sync( password, salt, iterations, keylen, digest )Parameters: This method accepts five parameters as mentioned above and described below: password: It is of type string, Buffer, TypedArray, or DataView.salt: It must be as unique as possible. However, it is recommended that a salt is arbitrary and in any case, it is at least 16 bytes long. It is of type string, Buffer, TypedArray, or DataView.iterations: It must be a number and should be set as high as possible. So, the more is the number of iterations, the more secure the derived key will be, but in that case, it takes a greater amount of time to complete. It is of type number.keylen: It is the key of the required byte length and it is of type number.digest: It is a digest algorithm of string type.Return Type: It returns the derived key as buffer. The below examples illustrate the use of crypto.pbkdf2Sync() method in Node.js: Example 1: javascript // Node.js program to demonstrate the // crypto.pbkdf2Sync() method // Including crypto module const crypto = require('crypto'); // Implementing pbkdf2Sync const key = crypto.pbkdf2Sync('secret', 'salt', 2000, 64, 'sha512'); // Prints buffer console.log(key); Output: <Buffer 3c f1 85 49 62 52 38 64 2a 4e b1 4c f6 25 2e 1e fc d7 8e 01 c9 40 d7 84 63 5e 24 ef 71 0f 91 83 bb 6d 03 bd 73 43 33 ec 78 a9 78 c8 1f ea7a dc 8c a6 ...>Example 2: javascript // Node.js program to demonstrate the // crypto.pbkdf2Sync() method // Including crypto module const crypto = require('crypto'); // Implementing pbkdf2Sync const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 100, 'sha512'); // Prints key which is encoded and converted // to string console.log(key.toString('hex')); Output: 3745e482c6e0ade35da10139e797157f4a5da669dad7d5da88ef87e4 7471cc47ed941c7ad618e827304f083f8707f12b7cfdd5f489b782f10cc269 e3c08d59ae04919ee902c99dba309cde75569fbe8e6d5c341d6f2576f6618c 589e77911a261ee964e2Reference: https://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2sync_password_salt_iterations_keylen_digest Comment More infoAdvertise with us nidhi1352singh Follow Improve Article Tags : Web Technologies Node.js Node.js-crypto-module Similar Reads Node.js cipher.final() Method The cipher.final() method in Node.js is used to signal to the cipher object that the encryption or decryption process is complete. This method must be called after all data has been passed to the cipher object using the cipher.update() method. The cipher.final() method returns the remaining encrypte 2 min read Node.js cipher.update() Method The cipher.update() method is an inbuilt application programming interface of class Cipher within crypto module which is used to update the cipher with data according to the given encoding format. Syntax: const cipher.update(data[, inputEncoding][, outputEncoding]) Parameters: This method takes the 2 min read Node.js crypto.getCiphers() Method The crypto.getCiphers() method returns an array the names of all the supported cipher algorithms. Syntax: crypto.getCiphers() Parameters: This method doesn't accepts any parameters. Return Value: It returns the names of all the supported cipher algorithms. Below example illustrate the use of crypto. 2 min read Node.js crypto.createECDH() Method The crypto.createECDH() method is an inbuilt application programming interface of crypto module which is used to create an Elliptic Curve Diffie-Hellman i.e, (ECDH) key exchange object with the help of a predefined curve which is defined by the curveName string. Moreover you can use crypto.getCurves 2 min read Node.js crypto.createDecipheriv() Method The crypto.createDecipheriv() method is an inbuilt application programming interface of crypto module which is used to create a Decipher object, with the stated algorithm, key and initialization vector i.e, (iv). Syntax: crypto.createDecipheriv( algorithm, key, iv, options ) Parameters: This method 3 min read Node crypto.createCipheriv() Method The crypto.createCipheriv() method is an inbuilt application programming interface of the crypto module which is used to create a Cipher object, with the stated algorithm, key, and initialization vector (iv).Syntax: crypto.createCipheriv( algorithm, key, iv, options )Parameters: This method accepts 2 min read Node.js crypto.getDiffieHellman() Method The crypto.getDiffieHellman() method is used to create a predefined DiffieHellmanGroup key exchange object. Here, the favored groups are 'modp1', 'modp2', 'modp5', which are defined in RFC 2412 and 'modp14', 'modp15', 'modp16', 'modp17', 'modp18', defined in RFC 3526. Syntax: crypto.getDiffieHellman 2 min read Node.js crypto.pbkdf2() Method The crypto.pbkdf2() method gives an asynchronous Password-Based Key Derivation Function 2 i.e. (PBKDF2) implementation. Moreover, a particular HMAC digest algorithm which is defined by digest is implemented to derive a key of the required byte length (keylen) from the stated password, salt, and iter 2 min read Node crypto.createHash() Method The crypto.createHash() method is used to create a Hash object that can be used to create hash digests by using the stated algorithm. Syntax:crypto.createHash( algorithm, options )Parameters: This method accepts two parameters as mentioned above and described below:algorithm: It is dependent on the 2 min read Node.js crypto.createHmac() Method The crypto.createHmac() method is used to create an Hmac object that uses the stated 'algorithm' and 'key'.Syntax:crypto.createHmac( algorithm, key, options )Parameters: This method accepts three parameters as mentioned above and described below:algorithm: It is dependent on the accessible algorithm 2 min read Like