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