diff --git a/doc/api/crypto.md b/doc/api/crypto.md index e43f3fa5dafc43..8be0bb53edc0a4 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1307,6 +1307,9 @@ API using additional attributes. @@ -2381,10 +2389,18 @@ must be an object with the properties described above. If the private key is encrypted, a `passphrase` must be specified. The length of the passphrase is limited to 1024 bytes. +If the `asymmetricKeyType` is specified, Node.js will attempt to assign the +given type to the key. This can be used, for example, to distinguish between +EC keys on the SM2 curve (`'ec'`) and SM2 keys (`'sm2'`). If the given type +cannot be assigned to the key, the function fails. + ### `crypto.createPublicKey(key)` @@ -2415,6 +2432,11 @@ otherwise, `key` must be an object with the properties described above. If the format is `'pem'`, the `'key'` may also be an X.509 certificate. +If the `asymmetricKeyType` is specified, Node.js will attempt to assign the +given type to the key. This can be used, for example, to distinguish between +EC keys on the SM2 curve (`'ec'`) and SM2 keys (`'sm2'`). If the given type +cannot be assigned to the key, the function fails. + Because public keys can be derived from private keys, a private key may be passed instead of a public key. In that case, this function behaves as if [`crypto.createPrivateKey()`][] had been called, except that the type of the @@ -2555,6 +2577,9 @@ console.log(key.export().toString('hex')); // e89..........41e * `type`: {string} Must be `'rsa'`, `'dsa'`, `'ec'`, `'ed25519'`, `'ed448'`, - `'x25519'`, `'x448'`, or `'dh'`. + `'x25519'`, `'x448'`, `'dh'`, or `'sm2'`. * `options`: {Object} * `modulusLength`: {number} Key size in bits (RSA, DSA). * `publicExponent`: {number} Public exponent (RSA). **Default:** `0x10001`. @@ -2592,7 +2617,7 @@ changes: * `privateKey`: {string | Buffer | KeyObject} Generates a new asymmetric key pair of the given `type`. RSA, DSA, EC, Ed25519, -Ed448, X25519, X448, and DH are currently supported. +Ed448, X25519, X448, DH, and SM2 are currently supported. If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function behaves as if [`keyObject.export()`][] had been called on its result. Otherwise, @@ -2630,6 +2655,9 @@ a `Promise` for an `Object` with `publicKey` and `privateKey` properties. * `type`: {string} Must be `'rsa'`, `'dsa'`, `'ec'`, `'ed25519'`, `'ed448'`, - `'x25519'`, `'x448'`, or `'dh'`. + `'x25519'`, `'x448'`, `'dh'`, or `'sm2'`. * `options`: {Object} * `modulusLength`: {number} Key size in bits (RSA, DSA). * `publicExponent`: {number} Public exponent (RSA). **Default:** `0x10001`. @@ -2663,7 +2691,7 @@ changes: * `privateKey`: {string | Buffer | KeyObject} Generates a new asymmetric key pair of the given `type`. RSA, DSA, EC, Ed25519, -Ed448, X25519, X448, and DH are currently supported. +Ed448, X25519, X448, DH, and SM2 are currently supported. If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function behaves as if [`keyObject.export()`][] had been called on its result. Otherwise, @@ -3627,6 +3655,9 @@ Throws an error if FIPS mode is not available.