GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: improve HMAC key recommendations · nodejs/node@281dfaf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • crypto.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/crypto.md‎

Copy file name to clipboardExpand all lines: doc/api/crypto.md
+12-1Lines changed: 12 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3391,7 +3391,11 @@ On recent releases of OpenSSL, `openssl list -digest-algorithms` will
33913391
display the available digest algorithms.
33923392

33933393
The `key` is the HMAC key used to generate the cryptographic HMAC hash. If it is
3394-
a [`KeyObject`][], its type must be `secret`.
3394+
a [`KeyObject`][], its type must be `secret`. If it is a string, please consider
3395+
[caveats when using strings as inputs to cryptographic APIs][]. If it was
3396+
obtained from a cryptographically secure source of entropy, such as
3397+
[`crypto.randomBytes()`][] or [`crypto.generateKey()`][], its length should not
3398+
exceed the block size of `algorithm` (e.g., 512 bits for SHA-256).
33953399

33963400
Example: generating the sha256 HMAC of a file
33973401

@@ -3665,6 +3669,9 @@ generateKey('hmac', { length: 512 }, (err, key) => {
36653669
});
36663670
```
36673671

3672+
The size of a generated HMAC key should not exceed the block size of the
3673+
underlying hash function. See [`crypto.createHmac()`][] for more information.
3674+
36683675
### `crypto.generateKeyPair(type, options, callback)`
36693676

36703677
<!-- YAML
@@ -3935,6 +3942,9 @@ const key = generateKeySync('hmac', { length: 512 });
39353942
console.log(key.export().toString('hex')); // e89..........41e
39363943
```
39373944

3945+
The size of a generated HMAC key should not exceed the block size of the
3946+
underlying hash function. See [`crypto.createHmac()`][] for more information.
3947+
39383948
### `crypto.generatePrime(size[, options[, callback]])`
39393949

39403950
<!-- YAML
@@ -6030,6 +6040,7 @@ See the [list of SSL OP Flags][] for details.
60306040
[`crypto.createSecretKey()`]: #cryptocreatesecretkeykey-encoding
60316041
[`crypto.createSign()`]: #cryptocreatesignalgorithm-options
60326042
[`crypto.createVerify()`]: #cryptocreateverifyalgorithm-options
6043+
[`crypto.generateKey()`]: #cryptogeneratekeytype-options-callback
60336044
[`crypto.getCurves()`]: #cryptogetcurves
60346045
[`crypto.getDiffieHellman()`]: #cryptogetdiffiehellmangroupname
60356046
[`crypto.getHashes()`]: #cryptogethashes

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.