@@ -1877,122 +1877,6 @@ Use [`crypto.getHashes()`][] to obtain an array of names of the available
18771877signing algorithms. Optional ` options ` argument controls the
18781878` stream.Writable ` behavior.
18791879
1880- In some cases, a ` Verify ` instance can be created using the name of a signature
1881- algorithm, such as ` 'RSA-SHA256' ` , instead of a digest algorithm. This will use
1882- the corresponding digest algorithm. This does not work for all signature
1883- algorithms, such as ` 'ecdsa-with-SHA256' ` , so it is best to always use digest
1884- algorithm names.
1885-
1886- ### crypto.generateKeyPair(type, options, callback)
1887- <!-- YAML
1888- added: v10.12.0
1889- changes:
1890- - version: v11.6.0
1891- pr-url: https://github.com/nodejs/node/pull/24234
1892- description: The `generateKeyPair` and `generateKeyPairSync` functions now
1893- produce key objects if no encoding was specified.
1894- -->
1895- * ` type ` : {string} Must be ` 'rsa' ` , ` 'dsa' ` or ` 'ec' ` .
1896- * ` options ` : {Object}
1897- - ` modulusLength ` : {number} Key size in bits (RSA, DSA).
1898- - ` publicExponent ` : {number} Public exponent (RSA). ** Default:** ` 0x10001 ` .
1899- - ` divisorLength ` : {number} Size of ` q ` in bits (DSA).
1900- - ` namedCurve ` : {string} Name of the curve to use (EC).
1901- - ` publicKeyEncoding ` : {Object} See [ ` keyObject.export() ` ] [ ] .
1902- - ` privateKeyEncoding ` : {Object} See [ ` keyObject.export() ` ] [ ] .
1903- * ` callback ` : {Function}
1904- - ` err ` : {Error}
1905- - ` publicKey ` : {string | Buffer | KeyObject}
1906- - ` privateKey ` : {string | Buffer | KeyObject}
1907-
1908- Generates a new asymmetric key pair of the given ` type ` . Only RSA, DSA and EC
1909- are currently supported.
1910-
1911- If a ` publicKeyEncoding ` or ` privateKeyEncoding ` was specified, this function
1912- behaves as if [ ` keyObject.export() ` ] [ ] had been called on its result. Otherwise,
1913- the respective part of the key is returned as a [ ` KeyObject ` ] .
1914-
1915- It is recommended to encode public keys as ` 'spki' ` and private keys as
1916- ` 'pkcs8' ` with encryption for long-term storage:
1917-
1918- ``` js
1919- const { generateKeyPair } = require (' crypto' );
1920- generateKeyPair (' rsa' , {
1921- modulusLength: 4096 ,
1922- publicKeyEncoding: {
1923- type: ' spki' ,
1924- format: ' pem'
1925- },
1926- privateKeyEncoding: {
1927- type: ' pkcs8' ,
1928- format: ' pem' ,
1929- cipher: ' aes-256-cbc' ,
1930- passphrase: ' top secret'
1931- }
1932- }, (err , publicKey , privateKey ) => {
1933- // Handle errors and use the generated key pair.
1934- });
1935- ```
1936-
1937- On completion, ` callback ` will be called with ` err ` set to ` undefined ` and
1938- ` publicKey ` / ` privateKey ` representing the generated key pair.
1939-
1940- If this method is invoked as its [ ` util.promisify() ` ] [ ] ed version, it returns
1941- a ` Promise ` for an ` Object ` with ` publicKey ` and ` privateKey ` properties.
1942-
1943- ### crypto.generateKeyPairSync(type, options)
1944- <!-- YAML
1945- added: v10.12.0
1946- changes:
1947- - version: v11.6.0
1948- pr-url: https://github.com/nodejs/node/pull/24234
1949- description: The `generateKeyPair` and `generateKeyPairSync` functions now
1950- produce key objects if no encoding was specified.
1951- -->
1952- * ` type ` : {string} Must be ` 'rsa' ` , ` 'dsa' ` or ` 'ec' ` .
1953- * ` options ` : {Object}
1954- - ` modulusLength ` : {number} Key size in bits (RSA, DSA).
1955- - ` publicExponent ` : {number} Public exponent (RSA). ** Default:** ` 0x10001 ` .
1956- - ` divisorLength ` : {number} Size of ` q ` in bits (DSA).
1957- - ` namedCurve ` : {string} Name of the curve to use (EC).
1958- - ` publicKeyEncoding ` : {Object} See [ ` keyObject.export() ` ] [ ] .
1959- - ` privateKeyEncoding ` : {Object} See [ ` keyObject.export() ` ] [ ] .
1960- * Returns: {Object}
1961- - ` publicKey ` : {string | Buffer | KeyObject}
1962- - ` privateKey ` : {string | Buffer | KeyObject}
1963-
1964- Generates a new asymmetric key pair of the given ` type ` . Only RSA, DSA and EC
1965- are currently supported.
1966-
1967- If a ` publicKeyEncoding ` or ` privateKeyEncoding ` was specified, this function
1968- behaves as if [ ` keyObject.export() ` ] [ ] had been called on its result. Otherwise,
1969- the respective part of the key is returned as a [ ` KeyObject ` ] .
1970-
1971- When encoding public keys, it is recommended to use ` 'spki' ` . When encoding
1972- private keys, it is recommended to use ` 'pks8' ` with a strong passphrase, and to
1973- keep the passphrase confidential.
1974-
1975- ``` js
1976- const { generateKeyPairSync } = require (' crypto' );
1977- const { publicKey , privateKey } = generateKeyPairSync (' rsa' , {
1978- modulusLength: 4096 ,
1979- publicKeyEncoding: {
1980- type: ' spki' ,
1981- format: ' pem'
1982- },
1983- privateKeyEncoding: {
1984- type: ' pkcs8' ,
1985- format: ' pem' ,
1986- cipher: ' aes-256-cbc' ,
1987- passphrase: ' top secret'
1988- }
1989- });
1990- ```
1991-
1992- The return value ` { publicKey, privateKey } ` represents the generated key pair.
1993- When PEM encoding was selected, the respective key will be a string, otherwise
1994- it will be a buffer containing the data encoded as DER.
1995-
19961880### crypto.getCiphers()
19971881<!-- YAML
19981882added: v0.9.3
0 commit comments