1# Key Import Overview and Algorithm Specifications 2 3You can import an externally generated key (for example, a key generated after key agreement or generated by a server) into HUKS for management. Once a key is imported into HUKS, the plaintext can be accessed only in a secure environment in its lifecycle. This ensures that no one can obtain the plaintext of the key. 4 5A key can be imported in plaintext or in encrypted (wrapped) mode. 6 7 8## Plaintext Import 9 10Importing a key in plaintext may expose the plaintext to a non-secure environment. This import mode applies to lightweight devices or security-insensitive services. 11 12- Plaintext import is recommended to import the public key of an asymmetric key pair. 13 14- It is not recommended to import symmetric keys or asymmetric key pairs. 15 > **NOTE**<br> 16 > The mini-system devices support plaintext import but not encrypted import. 17 18## Encrypted Import 19 20In this mode, the key to be imported is encrypted (wrapped) and then imported to HUKS through an end-to-end encrypted transmission channel established between the service and HUKS. This mode applies to security-sensitive services due to higher security than plaintext import. However, it involves more complex key material and operations. 21 22- Encrypted import is recommended to import symmetric keys or asymmetric key pairs. 23 24The following figure illustrates the development sequence of encrypted import. 25 26 27 28During the encrypted import process, the following HUKS capabilities are called in sequence: 29* Generate an asymmetric key pair and export the public key for key agreement between devices. 30* Generate a symmetric key to encrypt the key to be imported. 31* Use the symmetric key to encrypt the key to be imported to generate the key ciphertext. 32* Imports the encrypted key. 33* Delete the intermediate keys used for encrypting the key to be imported. 34 35The [public key plaintext material returned by the key export API is encapsulated in X.509 format](huks-concepts.md#public-key-material-format). The key material in the key import API must be encapsulated in the **Length<sub>Data</sub>-Data** format, for example, [(Length<sub>part1</sub>Data<sub>part1</sub>)... (Length<sub>partn</sub>Data<sub>partn</sub>)]. 36 37> **NOTE** 38> 39> - The encrypted import supports key agreement algorithms ECDH and X25519. The generated **Shared_Key** uses the AES-GCM algorithm to encrypt **Caller_Kek**. For details about the cipher suites, see [HuksUnwrapSuite](../../reference/apis-universal-keystore-kit/js-apis-huks.md#huksunwrapsuite9). 40> - The mini-system devices support plaintext import but not encrypted import. 41 42### Key Material Format for Encrypted Import 43 44| Content| Length| 45| -------- | -------- | 46| Service public key **Caller_Pk** length (L<sub>Caller_Pk</sub>)| 4 bytes| 47| Service public key **Caller_Pk**| L<sub>Caller_Pk</sub> bytes| 48| Shared_Key **AAD2** length (L<sub>AAD2</sub>)| 4 bytes| 49| Shared_Key **AAD2**| L<sub>AAD2</sub> bytes| 50| Shared_Key **Nonce2** length (L<sub>Nonce2</sub>)| 4 bytes| 51| Shared_Key **Nonce2**| L<sub>Nonce2</sub> bytes| 52| Shared_Key **AEAD2** length (L<sub>AEAD2</sub>)| 4 bytes| 53| Shared_Key **AEAD2**| L<sub>AEAD2</sub> bytes| 54| **Caller_Kek_enc** length (L<sub>Caller_Kek_enc</sub>)| 4 bytes| 55| Caller_Kek ciphertext **Caller_Kek_enc**| L<sub>Caller_Kek_enc</sub> bytes| 56| Caller_Kek **AAD3** length (L<sub>AAD3</sub>)| 4 bytes| 57| Caller_Kek **AAD3**| L<sub>AAD3</sub> bytes| 58| Caller_Kek **Nonce3** length (L<sub>Nonce3</sub>)| 4 bytes| 59| Caller_Kek **Nonce3**| L<sub>Nonce3</sub> bytes| 60| Caller_Kek **AEAD3** length (L<sub>AEAD3</sub>)| 4 bytes| 61| Caller_Kek **AEAD3**| L<sub>AEAD3</sub> bytes| 62| **To_Import_Key_size** length (L<sub>To_Import_Key_size</sub>)| 4 bytes| 63| Key plaintext material length **To_Import_Key_size**| L<sub>To_Import_Key_size</sub> bytes| 64| **To_Import_Key_enc** length (L<sub>To_Import_Key_enc</sub>)| 4 bytes| 65| To_Import_Key ciphertext **To_Import_Key_enc**| L<sub>To_Import_Key_enc</sub> bytes| 66 67 68## Supported Algorithms 69 70The following table lists the supported key import specifications. 71<!--Del--> 72The key management service specifications include mandatory specifications and optional specifications. Mandatory specifications are algorithm specifications that must be supported. Optional specifications can be used based on actual situation. Before using the optional specifications, refer to the documents provided by the vendor to ensure that the specifications are supported. 73 74**You are advised to use mandatory specifications in your development for compatibility purposes.** 75<!--DelEnd--> 76**Specifications for Standard-System Devices** 77| Algorithm| Supported Key Length (Bit)| API Version| <!--DelCol4-->Mandatory| 78| -------- | -------- | -------- | -------- | 79| AES | 128, 192, 256| 8+ | Yes| 80| <!--DelRow-->RSA | 512, 768, 1024| 8+ | No| 81| RSA | 2048, 3072, 4096| 8+ | Yes| 82| HMAC | An integer multiple of 8, ranging from 8 to 1024 (inclusive)| 8+ | Yes| 83| <!--DelRow-->ECC | 224 | 8+ | No| 84| ECC | 256, 384, 521| 8+ | Yes| 85| ED25519 | 256 | 8+ | Yes| 86| X25519 | 256 | 8+ | Yes| 87| <!--DelRow-->DSA | An integer multiple of 8, ranging from 512 to 1024 (inclusive) | 8+ | No| 88| DH | 2048 | 8+ | Yes| 89| <!--DelRow-->DH | 3072, 4096| 8+ | No| 90| SM2 | 256 | 9+ | Yes| 91| SM4 | 128 | 9+ | Yes| 92 93**Specifications for Mimi-System Devices** 94 95<!--Del--> 96Before implementing the specifications for mini-system devices, determine whether your device supports the related specifications. 97<!--DelEnd--> 98 99| Algorithm| Supported Key Length (Bit)| API Version| 100| -------- | -------- | -------- | 101| AES | 128, 192, 256| 12+ | 102| DES | 64 | 12+ | 103| 3DES | 128, 192| 12+ | 104| RSA | An integer multiple of 8, ranging from 1024 to 2048 (inclusive)| 12+ | 105| HMAC | An integer multiple of 8, ranging from 8 to 1024 (inclusive)| 12+ | 106| CMAC | 128 | 12+ | 107 108## Key Import Formats 109HUKS supports various types of keys in different formats. The following table lists the key types and key material formats supported by HUKS. 110| Key Type| Algorithm| Import Format| 111| -------- | -------- | -------- | 112| Symmetric key| - | Key in bytes| 113| Asymmetric key pair| - | [Key pair material format](huks-concepts.md#key-pair-material-format)| 114| Public key of an asymmetric key pair| Ed25519, X25519| See [Importing the X25519 Key and Public Key](huks-import-key-in-plaintext-arkts.md#importing-the-public-key-of-an-x25519-key-pair).| 115| Public key of an asymmetric key pair| RSA, ECC, ECDH, DSA, DH, SM2| DER format defined in X.509| 116