Skip to content

Commit 4849a54

Browse files
tomgcorvagg
authored andcommitted
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. PR-URL: #3290 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Shigeki Ohtsu <[email protected]>
1 parent 77251d9 commit 4849a54

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

doc/api/crypto.markdown

+9-1
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,16 @@ Asynchronous PBKDF2 function. Applies the selected HMAC digest function
620620
salt and number of iterations. The callback gets two arguments:
621621
`(err, derivedKey)`.
622622

623+
The number of iterations passed to pbkdf2 should be as high as possible, the
624+
higher the number, the more secure it will be, but will take a longer amount of
625+
time to complete.
626+
627+
Chosen salts should also be unique. It is recommended that the salts are random
628+
and their length is greater than 16 bytes. See [NIST SP 800-132] for details.
629+
623630
Example:
624631

625-
crypto.pbkdf2('secret', 'salt', 4096, 64, 'sha256', function(err, key) {
632+
crypto.pbkdf2('secret', 'salt', 100000, 512, 'sha512', function(err, key) {
626633
if (err)
627634
throw err;
628635
console.log(key.toString('hex')); // 'c5e478d...1469e50'
@@ -789,6 +796,7 @@ See the reference for other recommendations and details.
789796
[RFC 3526]: http://www.rfc-editor.org/rfc/rfc3526.txt
790797
[crypto.pbkdf2]: #crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
791798
[EVP_BytesToKey]: https://www.openssl.org/docs/crypto/EVP_BytesToKey.html
799+
[NIST SP 800-132]: http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf
792800
[NIST SP 800-131A]: http://csrc.nist.gov/publications/nistpubs/800-131A/sp800-131A.pdf
793801
[initialization vector]: http://en.wikipedia.org/wiki/Initialization_vector
794802
[Caveats]: #crypto_caveats

0 commit comments

Comments
 (0)