Skip to content

Commit e1b39b0

Browse files
committed
doc: Adding best practises for crypto.pbkdf2
Added some information around usages of how to use iterations, how to choose decent salts and updating the example to have a significant work factor and to use sha512.
1 parent 017fc5b commit e1b39b0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doc/api/crypto.markdown

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,16 @@ Asynchronous PBKDF2 function. Applies the selected HMAC digest function
625625
salt and number of iterations. The callback gets two arguments:
626626
`(err, derivedKey)`.
627627

628+
The number of iterations passed to pbkdf2 should be as high as possible, the
629+
higher the number, the more secure it will be, but will take a longer amount of
630+
time to complete.
631+
632+
Chosen salts should also be unique. It is recommended that the salts are random
633+
and their length is greater than 16 bytes. See NIST 800-132 for details.
634+
628635
Example:
629636

630-
crypto.pbkdf2('secret', 'salt', 4096, 64, 'sha256', function(err, key) {
637+
crypto.pbkdf2('secret', 'salt', 100000, 512, 'sha512', function(err, key) {
631638
if (err)
632639
throw err;
633640
console.log(key.toString('hex')); // 'c5e478d...1469e50'

0 commit comments

Comments
 (0)