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