1e41f4b71Sopenharmony_ci# Converting Binary Data into an Asymmetric Key Pair (ArkTS) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciThis topic uses RSA, ECC, and SM2 as an example to describe how to convert binary data into an asymmetric key pair (**KeyPair**). That is, convert a piece of external or internal binary data into a **KeyPair** object for subsequent operations, such as encryption and decryption. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci> **NOTE** 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> The asymmetric key conversion must comply with the following requirements: 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> - The public key must use the ASN.1 syntax and DER encoding format and comply with X.509 specifications. 12e41f4b71Sopenharmony_ci> 13e41f4b71Sopenharmony_ci> - The private key must use the ASN.1 syntax and DER encoding format and comply with PKCS\#8 specifications. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## Converting Binary Data into an RSA Key Pair 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciFor details about the algorithm specifications, see [RSA](crypto-asym-key-generation-conversion-spec.md#rsa). 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci1. Obtain the binary data of the RSA public key or private key and encapsulate the data into a **DataBlob** object. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci Either the public key or private key can be passed in. In this example, the public key is passed in. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci2. Use [cryptoFramework.createAsyKeyGenerator](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#cryptoframeworkcreateasykeygenerator) with the string parameter **'RSA1024'** to create an asymmetric key generator (**AsyKeyGenerator**) object for a 1024-bit RSA key with two primes. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci The default number of primes for creating an RSA asymmetric key is **2**. The **PRIMES_2** parameter is omitted in the string parameter here. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci3. Use [AsyKeyGenerator.convertKey](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#convertkey-3) to convert the binary data into an asymmetric key pair (**KeyPair**). 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci- Example: Convert binary data into an RSA key pair (using callback-based APIs). 31e41f4b71Sopenharmony_ci ```ts 32e41f4b71Sopenharmony_ci import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci function convertAsyKey() { 35e41f4b71Sopenharmony_ci let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); 36e41f4b71Sopenharmony_ci let pkVal = new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 174, 203, 113, 83, 113, 3, 143, 213, 194, 79, 91, 9, 51, 142, 87, 45, 97, 65, 136, 24, 166, 35, 5, 179, 42, 47, 212, 79, 111, 74, 134, 120, 73, 67, 21, 19, 235, 80, 46, 152, 209, 133, 232, 87, 192, 140, 18, 206, 27, 106, 106, 169, 106, 46, 135, 111, 118, 32, 129, 27, 89, 255, 183, 116, 247, 38, 12, 7, 238, 77, 151, 167, 6, 102, 153, 126, 66, 28, 253, 253, 216, 64, 20, 138, 117, 72, 15, 216, 178, 37, 208, 179, 63, 204, 39, 94, 244, 170, 48, 190, 21, 11, 73, 169, 156, 104, 193, 3, 17, 100, 28, 60, 50, 92, 235, 218, 57, 73, 119, 19, 101, 164, 192, 161, 197, 106, 105, 73, 2, 3, 1, 0, 1]); 37e41f4b71Sopenharmony_ci let pkBlob: cryptoFramework.DataBlob = { data: pkVal }; 38e41f4b71Sopenharmony_ci rsaGenerator.convertKey(pkBlob, null, (err, keyPair) => { 39e41f4b71Sopenharmony_ci if (err) { 40e41f4b71Sopenharmony_ci console.error(`convertKey failed, ${err.code}, ${err.message}`); 41e41f4b71Sopenharmony_ci return; 42e41f4b71Sopenharmony_ci } 43e41f4b71Sopenharmony_ci console.info('convertKey success'); 44e41f4b71Sopenharmony_ci }); 45e41f4b71Sopenharmony_ci } 46e41f4b71Sopenharmony_ci ``` 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci- Example: Convert binary data into an RSA key pair (using the synchronous API [convertKeySync](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#convertkeysync12)). 49e41f4b71Sopenharmony_ci ```ts 50e41f4b71Sopenharmony_ci import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci function convertAsyKeySync() { 53e41f4b71Sopenharmony_ci let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); 54e41f4b71Sopenharmony_ci let pkVal = new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 174, 203, 113, 83, 113, 3, 143, 213, 194, 79, 91, 9, 51, 142, 87, 45, 97, 65, 136, 24, 166, 35, 5, 179, 42, 47, 212, 79, 111, 74, 134, 120, 73, 67, 21, 19, 235, 80, 46, 152, 209, 133, 232, 87, 192, 140, 18, 206, 27, 106, 106, 169, 106, 46, 135, 111, 118, 32, 129, 27, 89, 255, 183, 116, 247, 38, 12, 7, 238, 77, 151, 167, 6, 102, 153, 126, 66, 28, 253, 253, 216, 64, 20, 138, 117, 72, 15, 216, 178, 37, 208, 179, 63, 204, 39, 94, 244, 170, 48, 190, 21, 11, 73, 169, 156, 104, 193, 3, 17, 100, 28, 60, 50, 92, 235, 218, 57, 73, 119, 19, 101, 164, 192, 161, 197, 106, 105, 73, 2, 3, 1, 0, 1]); 55e41f4b71Sopenharmony_ci let pkBlob: cryptoFramework.DataBlob = { data: pkVal }; 56e41f4b71Sopenharmony_ci try { 57e41f4b71Sopenharmony_ci let keyPair = rsaGenerator.convertKeySync(pkBlob, null); 58e41f4b71Sopenharmony_ci if (keyPair != null) { 59e41f4b71Sopenharmony_ci console.info('convertKeySync success'); 60e41f4b71Sopenharmony_ci } 61e41f4b71Sopenharmony_ci } catch (e) { 62e41f4b71Sopenharmony_ci console.error(`get key pair failed, ${e.code}, ${e.message}`); 63e41f4b71Sopenharmony_ci } 64e41f4b71Sopenharmony_ci } 65e41f4b71Sopenharmony_ci ``` 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci## Converting Binary Data into an ECC Key Pair 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ciFor details about the algorithm specifications, see [ECC](crypto-asym-key-generation-conversion-spec.md#ecc). 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci1. Obtain the binary data of the ECC public key or private key and encapsulate the data into a **DataBlob** object. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci Either the public key or private key can be passed in. As shown in the following example, the public key and private key are passed in separately. 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci2. Use [cryptoFramework.createAsyKeyGenerator](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#cryptoframeworkcreateasykeygenerator) with the string parameter **'ECC256'** to create an asymmetric key generator (**AsyKeyGenerator**) object for a 256-bit ECC key pair. 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci3. Use [AsyKeyGenerator.convertKey](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#convertkey-3) to convert the binary data into an asymmetric key pair (**KeyPair**). 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci- Example: Convert binary data into an ECC key pair (using callback-based APIs). 81e41f4b71Sopenharmony_ci ```ts 82e41f4b71Sopenharmony_ci import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci function convertEccAsyKey() { 85e41f4b71Sopenharmony_ci let pubKeyArray = new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); 86e41f4b71Sopenharmony_ci let priKeyArray = new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); 87e41f4b71Sopenharmony_ci let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; 88e41f4b71Sopenharmony_ci let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; 89e41f4b71Sopenharmony_ci let generator = cryptoFramework.createAsyKeyGenerator('ECC256'); 90e41f4b71Sopenharmony_ci generator.convertKey(pubKeyBlob, priKeyBlob, (error, data) => { 91e41f4b71Sopenharmony_ci if (error) { 92e41f4b71Sopenharmony_ci console.error(`convertKey failed, ${error.code}, ${error.message}`); 93e41f4b71Sopenharmony_ci return; 94e41f4b71Sopenharmony_ci } 95e41f4b71Sopenharmony_ci console.info('convertKey success'); 96e41f4b71Sopenharmony_ci }); 97e41f4b71Sopenharmony_ci } 98e41f4b71Sopenharmony_ci ``` 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci- Example: Convert binary data into an ECC key pair (using the synchronous API [convertKeySync](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#convertkeysync12)). 101e41f4b71Sopenharmony_ci ```ts 102e41f4b71Sopenharmony_ci import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci function convertECCAsyKeySync() { 105e41f4b71Sopenharmony_ci let pubKeyArray = new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); 106e41f4b71Sopenharmony_ci let priKeyArray = new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); 107e41f4b71Sopenharmony_ci let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; 108e41f4b71Sopenharmony_ci let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; 109e41f4b71Sopenharmony_ci let generator = cryptoFramework.createAsyKeyGenerator('ECC256'); 110e41f4b71Sopenharmony_ci try { 111e41f4b71Sopenharmony_ci let keyPair = generator.convertKeySync(pubKeyBlob, priKeyBlob); 112e41f4b71Sopenharmony_ci if (keyPair != null) { 113e41f4b71Sopenharmony_ci console.info('convertKeySync success'); 114e41f4b71Sopenharmony_ci } 115e41f4b71Sopenharmony_ci } catch (e) { 116e41f4b71Sopenharmony_ci console.error(`get key pair failed, ${e.code}, ${e.message}`); 117e41f4b71Sopenharmony_ci } 118e41f4b71Sopenharmony_ci } 119e41f4b71Sopenharmony_ci ``` 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci## Converting PKCS#8 Binary Data into an ECC Private Key 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ciFor details about the algorithm specifications, see [ECC](crypto-asym-key-generation-conversion-spec.md#ecc). 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ciObtain the binary data of the ECC public or private key, encapsulate the data into a **DataBlob** object, and convert the data into the ECC key format. 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci1. Use [cryptoFramework.createAsyKeyGenerator](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#cryptoframeworkcreateasykeygenerator) with the string parameter **'ECC256'** to create an asymmetric key generator (**AsyKeyGenerator**) object for a 256-bit ECC key pair. 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci2. Use [PubKey.getEncoded](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#getencoded) to obtain the byte stream of the public key data, and use [PriKey.getEncodeDer](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#getencodedder12-1) with **format** set to **'PKCS8'** to obtain the byte stream of the private key data. The binary data of the key object is obtained. 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci3. Use [AsyKeyGenerator.convertKey](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#convertkey-3) to convert the binary data into an asymmetric key pair. 132e41f4b71Sopenharmony_ci**Example** 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci ```ts 135e41f4b71Sopenharmony_ci import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci async function main() { 138e41f4b71Sopenharmony_ci // Create an AsyKeyGenerator instance. 139e41f4b71Sopenharmony_ci let eccGenerator = cryptoFramework.createAsyKeyGenerator('ECC256'); 140e41f4b71Sopenharmony_ci // Use AsyKeyGenerator to randomly generate an asymmetric key pair. 141e41f4b71Sopenharmony_ci let keyGenPromise = eccGenerator.generateKeyPair(); 142e41f4b71Sopenharmony_ci keyGenPromise.then(keyPair => { 143e41f4b71Sopenharmony_ci let pubKey = keyPair.pubKey; 144e41f4b71Sopenharmony_ci let priKey = keyPair.priKey; 145e41f4b71Sopenharmony_ci // Obtain the binary data of the ECC asymmetric key pair. 146e41f4b71Sopenharmony_ci let pubBlob = pubKey.getEncoded(); 147e41f4b71Sopenharmony_ci let skBlob = priKey.getEncodedDer('PKCS8'); 148e41f4b71Sopenharmony_ci let generator = cryptoFramework.createAsyKeyGenerator('ECC256'); 149e41f4b71Sopenharmony_ci generator.convertKey(pubBlob, skBlob, (error, data) => { 150e41f4b71Sopenharmony_ci if (error) { 151e41f4b71Sopenharmony_ci console.error(`convertKey failed, ${error.code}, ${error.message}`); 152e41f4b71Sopenharmony_ci return; 153e41f4b71Sopenharmony_ci } 154e41f4b71Sopenharmony_ci console.info('convertKey success'); 155e41f4b71Sopenharmony_ci }); 156e41f4b71Sopenharmony_ci }); 157e41f4b71Sopenharmony_ci } 158e41f4b71Sopenharmony_ci ``` 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci## Converting Binary Data into an SM2 Key Pair 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ciFor details about the algorithm specifications, see [SM2](crypto-asym-key-generation-conversion-spec.md#sm2). 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci1. Obtain the binary data of the SM2 public key or private key and encapsulate the data into a **DataBlob** object. 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci Either the public key or private key can be passed in. As shown in the following example, the public key and private key are passed in separately. 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci2. Use [cryptoFramework.createAsyKeyGenerator](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#cryptoframeworkcreateasykeygenerator) with the string parameter **'SM2_256'** to create an asymmetric key generator (**AsyKeyGenerator**) object for a 256-bit SM2 key pair. 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci3. Use [AsyKeyGenerator.convertKey](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#convertkey-3) to convert the binary data into an asymmetric key pair (**KeyPair**). 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci- Example: Convert binary data into an SM2 key pair (using callback-based APIs). 173e41f4b71Sopenharmony_ci ```ts 174e41f4b71Sopenharmony_ci import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci function convertSM2AsyKey() { 177e41f4b71Sopenharmony_ci let pubKeyArray = new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); 178e41f4b71Sopenharmony_ci let priKeyArray = new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45]); 179e41f4b71Sopenharmony_ci let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; 180e41f4b71Sopenharmony_ci let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; 181e41f4b71Sopenharmony_ci let generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); 182e41f4b71Sopenharmony_ci generator.convertKey(pubKeyBlob, priKeyBlob, (error, data) => { 183e41f4b71Sopenharmony_ci if (error) { 184e41f4b71Sopenharmony_ci console.error(`convertKey failed, ${error.code}, ${error.message}`); 185e41f4b71Sopenharmony_ci return; 186e41f4b71Sopenharmony_ci } 187e41f4b71Sopenharmony_ci console.info('convertKey success'); 188e41f4b71Sopenharmony_ci }); 189e41f4b71Sopenharmony_ci } 190e41f4b71Sopenharmony_ci ``` 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci- Example: Convert binary data into an SM2 key pair (using the synchronous API [convertKeySync](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#convertkeysync12)). 193e41f4b71Sopenharmony_ci ```ts 194e41f4b71Sopenharmony_ci import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci function convertSM2AsyKeySync() { 197e41f4b71Sopenharmony_ci let pubKeyArray = new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); 198e41f4b71Sopenharmony_ci let priKeyArray = new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45]); 199e41f4b71Sopenharmony_ci let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; 200e41f4b71Sopenharmony_ci let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; 201e41f4b71Sopenharmony_ci let generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); 202e41f4b71Sopenharmony_ci try { 203e41f4b71Sopenharmony_ci let keyPair = generator.convertKeySync(pubKeyBlob, priKeyBlob); 204e41f4b71Sopenharmony_ci if (keyPair != null) { 205e41f4b71Sopenharmony_ci console.info('convertKeySync success'); 206e41f4b71Sopenharmony_ci } 207e41f4b71Sopenharmony_ci } catch (e) { 208e41f4b71Sopenharmony_ci console.error(`get key pair failed, ${e.code}, ${e.message}`); 209e41f4b71Sopenharmony_ci } 210e41f4b71Sopenharmony_ci } 211e41f4b71Sopenharmony_ci ``` 212