1e41f4b71Sopenharmony_ci# Asymmetric Key Generation and Conversion Specifications 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciThis topic describes the supported algorithms and specifications for asymmetric key generation and conversion. The specifications for key generation can be specified via either of the following: 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci- String parameter: presents the specifications of the key to generate in the form of a string. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci- Key parameter: constructs the detailed cryptographic information of the key to generate in an object. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciFor details, see the specifications of each algorithm. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci## RSA 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ciRivest-Shamir-Adleman (RSA) is an asymmetric encryption algorithm widely used for secure data transmission. An RSA key can be generated based on a string parameter or key parameters. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci### String Parameter 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ciWhen creating an asymmetric key generator instance, you need to specify the key specifications in a string parameter. The string parameter consists of the RSA key type and prime count with a vertical bar (|) in between. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci> **NOTE** 23e41f4b71Sopenharmony_ci> When an RSA asymmetric key is generated, the default number of primes is 2 and the **PRIMES_2** parameter can be omitted. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| RSA Key Type| Prime Count| String Parameter| API Version| 26e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 27e41f4b71Sopenharmony_ci| RSA512 | 2 | RSA512\|PRIMES_2 | 9+ | 28e41f4b71Sopenharmony_ci| RSA768 | 2 | RSA768\|PRIMES_2 | 9+ | 29e41f4b71Sopenharmony_ci| RSA1024 | 2 | RSA1024\|PRIMES_2 | 9+ | 30e41f4b71Sopenharmony_ci| RSA1024 | 3 | RSA1024\|PRIMES_3 | 9+ | 31e41f4b71Sopenharmony_ci| RSA2048 | 2 | RSA2048\|PRIMES_2 | 9+ | 32e41f4b71Sopenharmony_ci| RSA2048 | 3 | RSA2048\|PRIMES_3 | 9+ | 33e41f4b71Sopenharmony_ci| RSA3072 | 2 | RSA3072\|PRIMES_2 | 9+ | 34e41f4b71Sopenharmony_ci| RSA3072 | 3 | RSA3072\|PRIMES_3 | 9+ | 35e41f4b71Sopenharmony_ci| RSA4096 | 2 | RSA4096\|PRIMES_2 | 9+ | 36e41f4b71Sopenharmony_ci| RSA4096 | 3 | RSA4096\|PRIMES_3 | 9+ | 37e41f4b71Sopenharmony_ci| RSA4096 | 4 | RSA4096\|PRIMES_4 | 9+ | 38e41f4b71Sopenharmony_ci| RSA8192 | 2 | RSA8192\|PRIMES_2 | 9+ | 39e41f4b71Sopenharmony_ci| RSA8192 | 3 | RSA8192\|PRIMES_3 | 9+ | 40e41f4b71Sopenharmony_ci| RSA8192 | 4 | RSA8192\|PRIMES_4 | 9+ | 41e41f4b71Sopenharmony_ci| RSA8192 | 5 | RSA8192\|PRIMES_5 | 9+ | 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci> **NOTE** 45e41f4b71Sopenharmony_ci> 46e41f4b71Sopenharmony_ci> It takes time to generate an RSA2048, RSA3072, RSA4096, or RSA8192 asymmetric key. Since the execution of the main thread has a time limit, the operation may fail if you use a synchronous API. You are advised to use asynchronous APIs or use [multithread concurrent tasks](../../arkts-utils/multi-thread-concurrency-overview.md) to generate a key of a large size. 47e41f4b71Sopenharmony_ci> 48e41f4b71Sopenharmony_ci> If the created RSA asymmetric key generator is used to randomly generate keys, the specifications of the RSA keys generated are the same as the key specifications set when the key generator is created. If it is used to convert keys, the specifications of the RSA keys generated are the same as the key specifications set in key conversion parameters. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci### Key Parameter 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ciSince API version 10, key parameters can be used to generate an RSA key. 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ciThe RSA key includes the following integers: 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci- **n**: modulus for both the private and public keys. 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci- **sk**: private exponent, which is often written as **d** in the formula. 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci- **pk**: public exponent, which is often written as **e** in the formula. 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ciThe following table illustrates the composition of the RSA key parameters. 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci- √ indicates the property used to construct a key parameter. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci- x indicates that the property that cannot be used to construct a key parameter. 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci| | Common Parameter| Public Key Parameter| Private Key Parameter| Key Pair Parameter| 69e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 70e41f4b71Sopenharmony_ci| n | × | √ | × | √ | 71e41f4b71Sopenharmony_ci| pk | - | √ | - | √ | 72e41f4b71Sopenharmony_ci| sk | - | - | × | √ | 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ciAccording to the preceding table: 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci- The RSA key cannot be generated based on the common parameter (**n**). 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci- The RSA private key cannot be generated based on the private key parameter, which consists of **n** and **sk**. 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci## ECC 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ciElliptic-curve cryptography (ECC) is a public-key encryption algorithm based on elliptic curve mathematics. 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ciThe ECC algorithm can be regarded as an operation of numbers defined in a special set. Currently, the Crypto framework supports only elliptic curves in the **Fp** field for ECC keys, where **p** indicates a prime. The **Fp** field is also called prime field. 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ciAn ECC key can be generated based on a string parameter or key parameters, and the common parameter can be generated based on the curve name. 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci### String Parameter 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ciWhen creating an asymmetric key generator instance, you need to specify the key specifications in a string parameter. The string parameter consists of the asymmetric key algorithm and key length. 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci| Asymmetric Key Algorithm| Key Length (Bit)| Curve Name| String Parameter| API Version| 95e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 96e41f4b71Sopenharmony_ci| ECC | 224 | NID_secp224r1 | ECC224 | 9+ | 97e41f4b71Sopenharmony_ci| ECC | 256 | NID_X9_62_prime256v1 | ECC256 | 9+ | 98e41f4b71Sopenharmony_ci| ECC | 384 | NID_secp384r1 | ECC384 | 9+ | 99e41f4b71Sopenharmony_ci| ECC | 521 | NID_secp521r1 | ECC521 | 9+ | 100e41f4b71Sopenharmony_ci| ECC | 160 | NID_brainpoolP160r1 | ECC_BrainPoolP160r1 | 11+ | 101e41f4b71Sopenharmony_ci| ECC | 160 | NID_brainpoolP160t1 | ECC_BrainPoolP160t1 | 11+ | 102e41f4b71Sopenharmony_ci| ECC | 192 | NID_brainpoolP192r1 | ECC_BrainPoolP192r1 | 11+ | 103e41f4b71Sopenharmony_ci| ECC | 192 | NID_brainpoolP192t1 | ECC_BrainPoolP192t1 | 11+ | 104e41f4b71Sopenharmony_ci| ECC | 224 | NID_brainpoolP224r1 | ECC_BrainPoolP224r1 | 11+ | 105e41f4b71Sopenharmony_ci| ECC | 224 | NID_brainpoolP224t1 | ECC_BrainPoolP224t1 | 11+ | 106e41f4b71Sopenharmony_ci| ECC | 256 | NID_brainpoolP256r1 | ECC_BrainPoolP256r1 | 11+ | 107e41f4b71Sopenharmony_ci| ECC | 256 | NID_brainpoolP256t1 | ECC_BrainPoolP256t1 | 11+ | 108e41f4b71Sopenharmony_ci| ECC | 320 | NID_brainpoolP320r1 | ECC_BrainPoolP320r1 | 11+ | 109e41f4b71Sopenharmony_ci| ECC | 320 | NID_brainpoolP320t1 | ECC_BrainPoolP320t1 | 11+ | 110e41f4b71Sopenharmony_ci| ECC | 384 | NID_brainpoolP384r1 | ECC_BrainPoolP384r1 | 11+ | 111e41f4b71Sopenharmony_ci| ECC | 384 | NID_brainpoolP384t1 | ECC_BrainPoolP384t1 | 11+ | 112e41f4b71Sopenharmony_ci| ECC | 512 | NID_brainpoolP512r1 | ECC_BrainPoolP512r1 | 11+ | 113e41f4b71Sopenharmony_ci| ECC | 512 | NID_brainpoolP512t1 | ECC_BrainPoolP512t1 | 11+ | 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci> **NOTE** 116e41f4b71Sopenharmony_ci> 117e41f4b71Sopenharmony_ci> If the created ECC asymmetric key generator is used to randomly generate keys, the specifications of the ECC keys generated are the same as the key specifications set when the key generator is created. If it is used to convert keys, the specifications of the ECC keys generated are the same as the key specifications set in key conversion parameters. 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci### Key Parameter 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciSince API version 10, key parameters can be used to generate an ECC key. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ciThe ECC key in the **Fp** field includes the following properties: 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci- **p**: prime used to determine **Fp**. 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci- **a**, **b**: determine the elliptic curve equation. 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci- **g**: base point of the elliptic curve, which can be represented as **gx** or **gy**. 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci- **n**: order of the base point **g**. 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci- **h**: cofactor. 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci- **sk**: private key, which is a random integer less than **n**. 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci- **pk**: public key, which is a point on the elliptic curve. **pk** = **sk** x **g**. 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ciThe following table illustrates the composition of the ECC key parameters. 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci- √ indicates the property used to construct a key parameter. 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci| | Common Parameter| Public Key Parameter| Private Key Parameter| Key Pair Parameter| 144e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 145e41f4b71Sopenharmony_ci| fieldType | √ | √ | √ | √ | 146e41f4b71Sopenharmony_ci| p | √ | √ | √ | √ | 147e41f4b71Sopenharmony_ci| a | √ | √ | √ | √ | 148e41f4b71Sopenharmony_ci| b | √ | √ | √ | √ | 149e41f4b71Sopenharmony_ci| g | √ | √ | √ | √ | 150e41f4b71Sopenharmony_ci| n | √ | √ | √ | √ | 151e41f4b71Sopenharmony_ci| h | √ | √ | √ | √ | 152e41f4b71Sopenharmony_ci| pk | - | √ | - | √ | 153e41f4b71Sopenharmony_ci| sk | - | - | √ | √ | 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci> **NOTE** 156e41f4b71Sopenharmony_ci> - Currently, only the **Fp** field is supported. Therefore, **fieldType** has a fixed value of **Fp**. **fieldType** and **p** constitute the property **field**, which supports only [ECFieldFp](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#ecfieldfp10) currently. 157e41f4b71Sopenharmony_ci> 158e41f4b71Sopenharmony_ci> - **g** and **pk** are points of the [Point](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#point10) type on the ECC curve. You need to specify their X and Y coordinates. 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci### Curve Name 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ciSince API version 11, the ECC common parameter can be generated based on a curve name. 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci> **NOTE** 167e41f4b71Sopenharmony_ci> - The curve name is a string parameter. For details about the supported curve names, see the **Curve Name** column in [ECC String Parameter](#string-parameter-1). 168e41f4b71Sopenharmony_ci> 169e41f4b71Sopenharmony_ci> - The generated common parameter can be used to randomly generate public and private keys, or used to construct the public key parameter, private key parameter, or key pair parameter. 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci## DSA 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ciDigital Signature Algorithm (DSA) is a public-key algorithm based on the modular exponentiation and discrete logarithm problem. It is used for digital signatures and signature verification, but not for encryption and decryption. 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ciA DSA key can be generated based on a string parameter or key parameters. 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci### Constraints 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ciIt takes time to generate a DSA2048 or DSA3072 asymmetric key pair or when the plaintext length exceeds 2048 bits. Since the execution of the main thread has a time limit, the operation may fail if you use a synchronous API. You are advised to use asynchronous APIs or use [multithread concurrent tasks](../../arkts-utils/multi-thread-concurrency-overview.md) to generate a key of a large size. 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci### String Parameter 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ciWhen creating an asymmetric key generator instance, you need to specify the key specifications in a string parameter. The string parameter consists of the asymmetric key algorithm and key length. 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci| Asymmetric Key Algorithm| Key Length (Bit)| String Parameter| API Version| 187e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 188e41f4b71Sopenharmony_ci| DSA | 1024 | DSA1024 | 10+ | 189e41f4b71Sopenharmony_ci| DSA | 2048 | DSA2048 | 10+ | 190e41f4b71Sopenharmony_ci| DSA | 3072 | DSA3072 | 10+ | 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci> **NOTE** 193e41f4b71Sopenharmony_ci> 194e41f4b71Sopenharmony_ci> It takes time to generate a DSA2048 or DSA3072 asymmetric key pair or when the plaintext length exceeds 2048 bits. Since the execution of the main thread has a time limit, the operation may fail if you use a synchronous API. You are advised to use asynchronous APIs or use [multithread concurrent tasks](../../arkts-utils/multi-thread-concurrency-overview.md) to generate a key of a large size. 195e41f4b71Sopenharmony_ci> 196e41f4b71Sopenharmony_ci> If the created DSA asymmetric key generator is used to randomly generate keys, the specifications of the DSA keys generated are the same as the key specifications set when the key generator is created. If it is used to convert keys, the specifications of the DSA keys generated are the same as the key specifications set in key conversion parameters. 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci### Key Parameter 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ciSince API version 10, key parameters can be used to generate a DSA key. 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ciThe DSA key includes the following properties: 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci- **p**: prime modulus, whose length is an integer multiple of 64. 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci- **q**: prime factor of **p** – 1. The length varies depending on the length of **p**. 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci- **g**: g = (h ^ ((p – 1)/q)) mod p, where **h** is an integer greater than 1 and less than **p** minus 1. 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci- **sk**: private key, which is a randomly generated integer greater than 0 and less than **q**. 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci- **pk**: public key. pk = (g ^ sk) mod p 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ciThe following table illustrates the composition of the DSA key parameters. 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci- √ indicates the property used to construct a key parameter. 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci- x indicates that the property that cannot be used to construct a key parameter. 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci| | Common Parameter| Public Key Parameter| Private Key Parameter| Key Pair Parameter| 221e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 222e41f4b71Sopenharmony_ci| p | √ | √ | × | √ | 223e41f4b71Sopenharmony_ci| q | √ | √ | × | √ | 224e41f4b71Sopenharmony_ci| g | √ | √ | × | √ | 225e41f4b71Sopenharmony_ci| pk | - | √ | - | √ | 226e41f4b71Sopenharmony_ci| sk | - | - | × | √ | 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci> **NOTE** 229e41f4b71Sopenharmony_ci> - The DSA private key cannot be generated based on the private key parameter, which consists of **p**, **q**, **g**, and **sk**. 230e41f4b71Sopenharmony_ci> 231e41f4b71Sopenharmony_ci> - When the common parameter (**p**, **q**, **g**) is used to generate a DSA key pair, the DSA key length must be at least 1024 bits. 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci## SM2 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ciShangMi 2 (SM2) is a public key cryptographic algorithm based on ECC. The SM2 algorithm uses the elliptic curves over the **Fp** field. 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ciAn SM2 key can be generated based on a string parameter or key parameters, and the common parameter can be generated based on the curve name. 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci### String Parameter 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ciWhen creating an asymmetric key generator instance, you need to specify the key specifications in a string parameter. The string parameter consists of the asymmetric key algorithm and key length with an underscore (_) in between. 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci| Asymmetric Key Algorithm| Key Length (Bit)| Curve Name| String Parameter| API Version| 246e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 247e41f4b71Sopenharmony_ci| SM2 | 256 | NID_sm2 | SM2_256 | 10+ | 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci### Key Parameter 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ciSince API version 11, key parameters can be used to generate an SM2 key. 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ciThe SM2 key in the **Fp** field includes the following properties: 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci- **p**: prime used to determine **Fp**. 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci- **a**, **b**: determine the elliptic curve equation. 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci- **g**: base point of the elliptic curve, which can be represented as **gx** or **gy**. 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci- **n**: order of the base point **g**. 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci- **h**: cofactor. 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci- **sk**: private key, which is a random integer less than **n**. 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci- **pk**: public key, which is a point on the elliptic curve. **pk** = **sk** x **g**. 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ciThe following table illustrates the composition of the SM2 key parameters. 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci- √ indicates the property used to construct a key parameter. 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci| | Common Parameter| Public Key Parameter| Private Key Parameter| Key Pair Parameter| 275e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 276e41f4b71Sopenharmony_ci| fieldType | √ | √ | √ | √ | 277e41f4b71Sopenharmony_ci| p | √ | √ | √ | √ | 278e41f4b71Sopenharmony_ci| a | √ | √ | √ | √ | 279e41f4b71Sopenharmony_ci| b | √ | √ | √ | √ | 280e41f4b71Sopenharmony_ci| g | √ | √ | √ | √ | 281e41f4b71Sopenharmony_ci| n | √ | √ | √ | √ | 282e41f4b71Sopenharmony_ci| h | √ | √ | √ | √ | 283e41f4b71Sopenharmony_ci| pk | - | √ | - | √ | 284e41f4b71Sopenharmony_ci| sk | - | - | √ | √ | 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci> **NOTE** 287e41f4b71Sopenharmony_ci> - Currently, only the **Fp** field is supported. Therefore, **fieldType** has a fixed value of **Fp**. **fieldType** and **p** constitute **field**, which supports only [ECFieldFp](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#ecfieldfp10) currently. 288e41f4b71Sopenharmony_ci> 289e41f4b71Sopenharmony_ci> - **g** and **pk** are points of the [Point](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#point10) type on the SM2 curve. You need to specify their X and Y coordinates. 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci### Curve Name 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ciSince API version 11, the SM2 common parameter can be generated based on a curve name. 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci> **NOTE** 298e41f4b71Sopenharmony_ci> - The curve name is a string parameter. The supported curve name is **NID_sm2**. 299e41f4b71Sopenharmony_ci> 300e41f4b71Sopenharmony_ci> - The generated common parameter can be used to randomly generate public and private keys, or used to construct the public key parameter, private key parameter, or key pair parameter. 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci## Ed25519 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ciEd25519 is a digital signature algorithm based on EdDSA. The key is of 256 bits and is implemented using Edwards curves. Ed25519 is used for signing and signature verification, and cannot be used for encryption or decryption. 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ciAn Ed25519 key can be generated based on a string parameter or key parameters. 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci### String Parameter 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ciWhen creating an asymmetric key generator instance, you need to specify the key specifications in a string parameter. 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci| Asymmetric Key Algorithm| String Parameter| API Version| 315e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 316e41f4b71Sopenharmony_ci| Ed25519 | Ed25519 | 11+ | 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci### Key Parameter 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ciSince API version 11, key parameters can be used to generate an Ed25519 key. 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ciThe Ed25519 key includes the following properties: 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci- **sk**: private key, which is a 32-byte random value. 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci- **pk**: public key, a 32-byte value derived from the private key. 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ciThe following table illustrates the composition of the Ed25519 key parameters. 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci- √ indicates the property used to construct a key parameter. 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci| | Public Key Parameter| Private Key Parameter| Key Pair Parameter| 334e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 335e41f4b71Sopenharmony_ci| pk | √ | - | √ | 336e41f4b71Sopenharmony_ci| sk | - | √ | √ | 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci> **NOTE** 339e41f4b71Sopenharmony_ci> Ed25519 does not have the common parameter. 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci## X25519 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ciX25519 is a Diffie-Hellman key exchange algorithm used for key agreement. 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ciAn X25519 key can be generated based on a string parameter or key parameters. 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci### String Parameter 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ciWhen creating an asymmetric key generator instance, you need to specify the key specifications in a string parameter. 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci| Asymmetric Key Algorithm| String Parameter| API Version| 354e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 355e41f4b71Sopenharmony_ci| X25519 | X25519 | 11+ | 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci### Key Parameter 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ciSince API version 11, key parameters can be used to generate an X25519 key. 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ciThe X22519 key includes the following properties: 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci- **sk**: private key, which is a 32-byte random value. 365e41f4b71Sopenharmony_ci 366e41f4b71Sopenharmony_ci- **pk**: public key, a 32-byte value derived from the private key. 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ciThe following table illustrates the composition of the X25519 key parameters. 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci- √ indicates the property used to construct a key parameter. 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci| | Public Key Parameter| Private Key Parameter| Key Pair Parameter| 373e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 374e41f4b71Sopenharmony_ci| pk | √ | - | √ | 375e41f4b71Sopenharmony_ci| sk | - | √ | √ | 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci> **NOTE** 378e41f4b71Sopenharmony_ci> X25519 does not have the common parameter. 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci## DH 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ciDiffie–Hellman key exchange (DH) is a key agreement algorithm used to exchange the public key only. It provides forward secrecy, which protects the session keys against compromises even if the communication channel is intercepted. 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ciA DH key can be generated based on a string parameter or key parameters, and the common parameter can be generated based on the prime length and private key length. 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci### String Parameter 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ciWhen creating an asymmetric key generator instance, you need to specify the key specifications in a string parameter. The string parameter consists of the asymmetric key algorithm and named DH group with an underscore (_) in between. 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci| Asymmetric Key Algorithm| Named DH Group| Key Length (Bit)| String Parameter| API Version| 393e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 394e41f4b71Sopenharmony_ci| DH | modp1536 | 1536 | DH_modp1536 | 11+ | 395e41f4b71Sopenharmony_ci| DH | modp2048 | 2048 | DH_modp2048 | 11+ | 396e41f4b71Sopenharmony_ci| DH | modp3072 | 3072 | DH_modp3072 | 11+ | 397e41f4b71Sopenharmony_ci| DH | modp4096 | 4096 | DH_modp4096 | 11+ | 398e41f4b71Sopenharmony_ci| DH | modp6144 | 6144 | DH_modp6144 | 11+ | 399e41f4b71Sopenharmony_ci| DH | modp8192 | 8192 | DH_modp8192 | 11+ | 400e41f4b71Sopenharmony_ci| DH | ffdhe2048 | 2048 | DH_ffdhe2048 | 11+ | 401e41f4b71Sopenharmony_ci| DH | ffdhe3072 | 3072 | DH_ffdhe3072 | 11+ | 402e41f4b71Sopenharmony_ci| DH | ffdhe4096 | 4096 | DH_ffdhe4096 | 11+ | 403e41f4b71Sopenharmony_ci| DH | ffdhe6144 | 6144 | DH_ffdhe6144 | 11+ | 404e41f4b71Sopenharmony_ci| DH | ffdhe8192 | 8192 | DH_ffdhe8192 | 11+ | 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci> **NOTE** 407e41f4b71Sopenharmony_ci> 408e41f4b71Sopenharmony_ci> If the created DH asymmetric key generator is used to randomly generate keys, the specifications of the DH keys generated are the same as the key specifications set when the key generator is created. If it is used to convert keys, the specifications of the DH keys generated are the same as the key specifications set in key conversion parameters. 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci### Key Parameter 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ciSince API version 11, key parameters can be used to generate a DH key. 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ciThe DH key includes the following properties: 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci- **p**: a large prime used as a modulus of a finite field. It is shared by all communicating parties. 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci- **g**: a primitive root modulo **p**. It is shared by all communicating parties. 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci- **l**: length of the private key, in bits. The value **0** means the length of the private key is not specified. 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci- **sk**: private key, which is a randomly generated value. 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci- **pk**: public key, which is calculated using the common parameter (**p** and **g**) and the private key. 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ciThe following table illustrates the composition of the DH key parameters. 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci- √ indicates the property used to construct a key parameter. 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci| | Common Parameter| Public Key Parameter| Private Key Parameter| Key Pair Parameter| 431e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 432e41f4b71Sopenharmony_ci| p | √ | √ | √ | √ | 433e41f4b71Sopenharmony_ci| g | √ | √ | √ | √ | 434e41f4b71Sopenharmony_ci| l | √ | √ | √ | √ | 435e41f4b71Sopenharmony_ci| pk | - | √ | - | √ | 436e41f4b71Sopenharmony_ci| sk | - | - | √ | √ | 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci### Common Parameter Generated Based on the Prime Length and Private Key Length 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ciSince API version 11, the DH common parameter can be generated based on the prime length and private key length. 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ciIf the prime length is the same as that of the DH group, the DH group is used. The following table lists the mappings between the prime lengths and DH groups. 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci| Prime Length (Bit)| Named DH Group| 446e41f4b71Sopenharmony_ci| -------- | -------- | 447e41f4b71Sopenharmony_ci| 2048 | ffdhe2048 | 448e41f4b71Sopenharmony_ci| 3072 | ffdhe3072 | 449e41f4b71Sopenharmony_ci| 4096 | ffdhe4096 | 450e41f4b71Sopenharmony_ci| 6144 | ffdhe6144 | 451e41f4b71Sopenharmony_ci| 8192 | ffdhe8192 | 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_ci- The number of bits for **p** must be greater than or equal to 512 and less than or equal to 10000. 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci- The parameter **l** (private key length) is optional. The default value is **0**. The value of **l** must meet the following requirements:<br>**l** > 2\*(96 + (Length of p – 1)/1024 x 16) 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci- The generated common parameter can be used to randomly generate public and private keys, or used to construct the public key parameter, private key parameter, or key pair parameter. 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci- Named DH groups are recommended because generating a key parameter with an unnamed DH group is time-consuming. 460