Skip to content

Commit 79460ba

Browse files
bmuenzenmeyerpanva
andauthored
doc: apply suggestions
Co-authored-by: Filip Skokan <panva.ip@gmail.com>
1 parent 391db51 commit 79460ba

1 file changed

Lines changed: 13 additions & 38 deletions

File tree

doc/api/crypto.md

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5522,58 +5522,33 @@ console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
55225522
added: REPLACEME
55235523
-->
55245524

5525-
* `bundle` {ArrayBuffer|Buffer|TypedArray|DataView} The DER-encoded PKCS#12
5526-
bundle.
5525+
* `bundle` {ArrayBuffer|Buffer|TypedArray|DataView} A DER-encoded PKCS#12
5526+
(`.p12` or `.pfx`) bundle.
55275527
* `options` {Object}
55285528
* `passphrase` {string|ArrayBuffer|Buffer|TypedArray|DataView} The passphrase
5529-
protecting the bundle. Omit for bundles with no passphrase. PKCS#12
5530-
encodes an absent and an empty passphrase differently, but OpenSSL tries
5531-
both, so omitting this option and passing `''` behave the same. The
5532-
passphrase must not contain a NUL byte; PKCS#12 passwords cannot
5533-
represent one, and passing one throws [`ERR_INVALID_ARG_VALUE`][].
5529+
protecting the bundle. Omitting this option is equivalent to passing `''`.
55345530
* Returns: {Object}
5535-
* `privateKey` {KeyObject|null} The private key, or `null` if the bundle
5536-
contains none.
5537-
* `certificate` {X509Certificate|null} The certificate associated with
5538-
`privateKey`, or `null` if the bundle contains none.
5539-
* `additionalCertificates` {X509Certificate\[]} Every other certificate in
5540-
the bundle. These are not necessarily certificate authorities; this is
5541-
whatever remains once `certificate` has been taken out. May be empty.
5531+
* `privateKey` {KeyObject|null} The first private key in the bundle, or
5532+
`null` if none is present.
5533+
* `certificate` {X509Certificate|null} The certificate matching `privateKey`,
5534+
or `null` if no matching certificate is present.
5535+
* `additionalCertificates` {X509Certificate\[]} All other certificates in
5536+
the bundle. If there is no private key, this contains all certificates.
5537+
May be empty.
55425538

5543-
Parses a PKCS#12 bundlecommonly seen with the `.p12` or `.pfx` extension
5544-
and returns its contents.
5539+
Parses a PKCS#12 bundle, commonly stored with a `.p12` or `.pfx` extension,
5540+
and returns its private key and certificates.
55455541

55465542
```mjs
55475543
import { parsePKCS12 } from 'node:crypto';
55485544
import { readFileSync } from 'node:fs';
55495545

5550-
const { privateKey, certificate } = parsePKCS12(
5546+
const { privateKey, certificate, additionalCertificates } = parsePKCS12(
55515547
readFileSync('bundle.p12'),
55525548
{ passphrase: 'secret' },
55535549
);
5554-
5555-
console.log(certificate.subject);
5556-
console.log(privateKey.export({ type: 'pkcs8', format: 'pem' }));
55575550
```
55585551

5559-
A PKCS#12 bundle may technically contain more than one private key. This API
5560-
returns only the first, matching the behavior of OpenSSL's `PKCS12_parse()`.
5561-
5562-
`certificate` is identified by its association with the private key. A bundle
5563-
containing no private key therefore reports `certificate` as `null` and returns
5564-
all of its certificates through `additionalCertificates`, including any
5565-
end-entity certificate the bundle holds.
5566-
5567-
Bundles encrypted with older algorithms — notably RC2 and PBE-SHA1 variants
5568-
produced by legacy Windows tooling and older versions of `keytool` — require
5569-
OpenSSL's legacy provider. Reading these throws an error with the code
5570-
[`ERR_CRYPTO_UNSUPPORTED_OPERATION`][]; starting Node.js with
5571-
[`--openssl-legacy-provider`][] may allow them to be read, subject to the
5572-
security implications of enabling that provider.
5573-
5574-
To use a PKCS#12 bundle directly for a TLS connection, prefer the `pfx` option
5575-
of [`tls.createSecureContext()`][] rather than parsing and re-supplying the
5576-
parts.
55775552

55785553
### `crypto.pbkdf2(password, salt, iterations, keylen, digest, callback)`
55795554

0 commit comments

Comments
 (0)