Node.js crypto.scryptSync( ) Function
The crypto.scryptSync() is an inbuilt function which Provides a synchronous scrypt implementation in Node.js. scrypt is a password-based key derivation function. It is intended to be costly computationally plus memory-wise. So, the brute-force attacks are made unsuccessful.
crypto.scryptSync(password, salt, keylen[, options])
Parameter: This method accept five parameters as mentioned above and described below:
- password: It can hold string, Buffer, TypedArray, or DataView type of data.
- salt: It holds string, Buffer, TypedArray, or DataView type of data. It must be as unique as possible. Moreover, it is recommended that salt should be random and is at a minimum of 16 bytes long.
- keylen: It denotes the length of the key, and it must be a number.
- options:It is of type Object, and it has seven parameters namely cost, blockSize, parallelization, N, r, p, and maxmem.
Return Value: It returns a buffer.
Below examples illustrate the use of crypto.scryptSync() method in Node.js:
The key in the form of buffer is : <Buffer d9 9d b7 7e 7c 25 cb 39 db 3b 16 6b b8 47 73 43 4e 96 72 9c 02 b3 55 7b 7d 66 f5 54 e6 e3 a0 e6> The key in the form of buffer is : <Buffer 26 c4 91 3f a7 03 b8 30 7a b5 bf a6 fe de 34 aa 46 8c b5 dd b6 0d ce 5a 5e 03 91 a1 7c 7d ba d0 5b d6 62 8e 11 3a 45 f6 41 a2 be b2 39 c9 57 5a 78 55 ... 14 more bytes>
The key in the form of ASCII is: k&q0Y4EQ_72 The key in the form of hex is : 29dcb56a3d91f7be66de7444bc7ac605