Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d16def5

Browse filesBrowse files
tomgcoShigeki Ohtsu
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 <fedor@indutny.com> Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
1 parent 615fba3 commit d16def5
Copy full SHA for d16def5

File tree

Expand file treeCollapse file tree

1 file changed

+9
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-1
lines changed
Open diff view settings
Collapse file

‎doc/api/crypto.markdown‎

Copy file name to clipboardExpand all lines: doc/api/crypto.markdown
+9-1Lines changed: 9 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.