1e41f4b71Sopenharmony_ci# @ohos.security.huks (Universal Keystore)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **huks** module provides KeyStore (KS) capabilities, including key management and cryptographic operations, for applications. The keys managed by OpenHarmony Universal KeyStore (HUKS) can be imported by applications or generated by calling the HUKS APIs.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Modules to Import
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## HuksParam
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciDefines the **param** field in the **properties** array of **options** used in the APIs.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| Name| Type                               | Mandatory| Description        |
24e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | ------------ |
25e41f4b71Sopenharmony_ci| tag    | [HuksTag](#hukstag)                 | Yes  | Tag.      |
26e41f4b71Sopenharmony_ci| value  | boolean\|number\|bigint\|Uint8Array | Yes  | Value of the tag.|
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci## HuksOptions
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ciDefines **options** used in the APIs. 
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci| Name    | Type             | Mandatory| Description                    |
37e41f4b71Sopenharmony_ci| ---------- | ----------------- | ---- | ------------------------ |
38e41f4b71Sopenharmony_ci| properties | Array\<[HuksParam](#huksparam)> | No  | Properties used to hold the **HuksParam** array.|
39e41f4b71Sopenharmony_ci| inData     | Uint8Array        | No  | Input data.              |
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci## HuksSessionHandle<sup>9+</sup>
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciDefines the struct for a HUKS handle.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci| Name   | Type      | Mandatory| Description                                                |
50e41f4b71Sopenharmony_ci| --------- | ---------- | ---- | ---------------------------------------------------- |
51e41f4b71Sopenharmony_ci| handle    | number     | Yes  | Value of the handle.                                      |
52e41f4b71Sopenharmony_ci| challenge | Uint8Array | No  | Challenge obtained after the [initSession](#huksinitsession9) operation.|
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci## HuksReturnResult<sup>9+</sup>
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ciRepresents the result returned.
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci| Name    | Type                           | Mandatory| Description            |
63e41f4b71Sopenharmony_ci| ---------- | ------------------------------- | ---- | ---------------- |
64e41f4b71Sopenharmony_ci| outData    | Uint8Array                      | No  | Output data.<br>**Atomic service API**: This API can be used in atomic services since API version 11. |
65e41f4b71Sopenharmony_ci| properties | Array\<[HuksParam](#huksparam)> | No  | Property information.<br>**Atomic service API**: This API can be used in atomic services since API version 11. |
66e41f4b71Sopenharmony_ci| certChains | Array\<string>                  | No  | Certificate chain information.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci## HuksListAliasesReturnResult<sup>12+</sup>
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ciRepresents an array of key aliases.
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci| Name    | Type                           | Mandatory| Description            |
79e41f4b71Sopenharmony_ci| ---------- | ------------------------------- | ---- | ---------------- |
80e41f4b71Sopenharmony_ci| keyAliases | Array\<string>                  | Yes  | Array of key aliases.|
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci## huks.generateKeyItem<sup>9+</sup>
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_cigenerateKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<void>) : void
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ciGenerates a key. This API uses an asynchronous callback to return the result.
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**Parameters**
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                         |
96e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | --------------------------------------------- |
97e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key.                                        |
98e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Tags required for generating the key. The algorithm, key purpose, and key length are mandatory.|
99e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>        | Yes  | Callback used to return the result. <br/>If the operation is successful, this API does not return the key content because the key is always protected in a TEE. <br/>If an exception occurs in the generation process, an error is captured.|
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**Error codes**
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci| ID| Error Message     |
106e41f4b71Sopenharmony_ci| -------- | ------------- |
107e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
108e41f4b71Sopenharmony_ci| 801 | api is not supported. |
109e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
110e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
111e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
112e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
113e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
114e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
115e41f4b71Sopenharmony_ci| 12000012 | external error. |
116e41f4b71Sopenharmony_ci| 12000013 | queried credential does not exist. |
117e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
118e41f4b71Sopenharmony_ci| 12000015 | call service failed. |
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**Example**
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci```ts
123e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
124e41f4b71Sopenharmony_ci/* Generate a 256-bit ECC key. */
125e41f4b71Sopenharmony_cilet keyAlias: string = 'keyAlias';
126e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> =[
127e41f4b71Sopenharmony_ci    {
128e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
129e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_ECC
130e41f4b71Sopenharmony_ci    },
131e41f4b71Sopenharmony_ci    {
132e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
133e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_ECC_KEY_SIZE_256
134e41f4b71Sopenharmony_ci    },
135e41f4b71Sopenharmony_ci    {
136e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
137e41f4b71Sopenharmony_ci        value:
138e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN |
139e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY
140e41f4b71Sopenharmony_ci    },
141e41f4b71Sopenharmony_ci    {
142e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_DIGEST,
143e41f4b71Sopenharmony_ci        value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
144e41f4b71Sopenharmony_ci    },
145e41f4b71Sopenharmony_ci];
146e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
147e41f4b71Sopenharmony_ci    properties: properties
148e41f4b71Sopenharmony_ci};
149e41f4b71Sopenharmony_citry {
150e41f4b71Sopenharmony_ci    huks.generateKeyItem(keyAlias, options, (error, data) => {
151e41f4b71Sopenharmony_ci        if (error) {
152e41f4b71Sopenharmony_ci            console.error(`callback: generateKeyItem failed`);
153e41f4b71Sopenharmony_ci        } else {
154e41f4b71Sopenharmony_ci            console.info(`callback: generateKeyItem key success`);
155e41f4b71Sopenharmony_ci        }
156e41f4b71Sopenharmony_ci    });
157e41f4b71Sopenharmony_ci} catch (error) {
158e41f4b71Sopenharmony_ci    console.error(`callback: generateKeyItem input arg invalid`);
159e41f4b71Sopenharmony_ci}
160e41f4b71Sopenharmony_ci```
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci## huks.generateKeyItem<sup>9+</sup>
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_cigenerateKeyItem(keyAlias: string, options: HuksOptions) : Promise\<void>
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ciGenerates a key. This API uses a promise to return the result. Because the key is always protected in a trusted environment (such as a TEE), the promise does not return the key content. It returns only the information indicating whether the API is successfully called.
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**Parameters**
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                    |
175e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------ |
176e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key.              |
177e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Tags required for generating the key. The algorithm, key purpose, and key length are mandatory.|
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci**Return value**
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci| Type                                          | Description                                         |
182e41f4b71Sopenharmony_ci| ---------------------------------------------- | --------------------------------------------- |
183e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci**Error codes**
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci| ID| Error Message     |
190e41f4b71Sopenharmony_ci| -------- | ------------- |
191e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
192e41f4b71Sopenharmony_ci| 801 | api is not supported. |
193e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
194e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
195e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
196e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
197e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
198e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
199e41f4b71Sopenharmony_ci| 12000012 | external error. |
200e41f4b71Sopenharmony_ci| 12000013 | queried credential does not exist. |
201e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
202e41f4b71Sopenharmony_ci| 12000015 | call service failed. |
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci**Example**
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci```ts
207e41f4b71Sopenharmony_ci/* Generate a 256-bit ECC key. */
208e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
209e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
210e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> =[
211e41f4b71Sopenharmony_ci    {
212e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
213e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_ECC
214e41f4b71Sopenharmony_ci    },
215e41f4b71Sopenharmony_ci    {
216e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
217e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_ECC_KEY_SIZE_256
218e41f4b71Sopenharmony_ci    },
219e41f4b71Sopenharmony_ci    {
220e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
221e41f4b71Sopenharmony_ci        value:
222e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN |
223e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY
224e41f4b71Sopenharmony_ci    },
225e41f4b71Sopenharmony_ci    {
226e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_DIGEST,
227e41f4b71Sopenharmony_ci        value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
228e41f4b71Sopenharmony_ci    },
229e41f4b71Sopenharmony_ci];
230e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
231e41f4b71Sopenharmony_ci    properties: properties
232e41f4b71Sopenharmony_ci};
233e41f4b71Sopenharmony_citry {
234e41f4b71Sopenharmony_ci    huks.generateKeyItem(keyAlias, options)
235e41f4b71Sopenharmony_ci        .then((data) => {
236e41f4b71Sopenharmony_ci            console.info(`promise: generateKeyItem success`);
237e41f4b71Sopenharmony_ci        })
238e41f4b71Sopenharmony_ci        .catch((error: Error) => {
239e41f4b71Sopenharmony_ci            console.error(`promise: generateKeyItem failed`);
240e41f4b71Sopenharmony_ci        });
241e41f4b71Sopenharmony_ci} catch (error) {
242e41f4b71Sopenharmony_ci    console.error(`promise: generateKeyItem input arg invalid`);
243e41f4b71Sopenharmony_ci}
244e41f4b71Sopenharmony_ci```
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci## huks.deleteKeyItem<sup>9+</sup>
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_cideleteKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<void>) : void
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ciDeletes a key. This API uses an asynchronous callback to return the result.
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci**Parameters**
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                         |
259e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | --------------------------------------------- |
260e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key to delete. It must be the key alias passed in when the key was generated.          |
261e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Options for deleting the key. For example, you can pass in [HuksAuthStorageLevel](#huksauthstoragelevel11) to specify the security level of the key to delete. **HuksAuthStorageLevel** can be left empty, which means the default value **HUKS_AUTH_STORAGE_LEVEL_DE** is used.                     |
262e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>        | Yes  | Callback used to return the result. If the operation is successful, no **err** value is returned; otherwise, an error code is returned.|
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci**Error codes**
265e41f4b71Sopenharmony_ci
266e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ci| ID| Error Message     |
269e41f4b71Sopenharmony_ci| -------- | ------------- |
270e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
271e41f4b71Sopenharmony_ci| 801 | api is not supported. |
272e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
273e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
274e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
275e41f4b71Sopenharmony_ci| 12000012 | external error. |
276e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci**Example**
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci```ts
281e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
282e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
283e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
284e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
285e41f4b71Sopenharmony_ci    properties: []
286e41f4b71Sopenharmony_ci};
287e41f4b71Sopenharmony_citry {
288e41f4b71Sopenharmony_ci    huks.deleteKeyItem(keyAlias, emptyOptions, (error, data) => {
289e41f4b71Sopenharmony_ci        if (error) {
290e41f4b71Sopenharmony_ci            console.error(`callback: deleteKeyItem failed`);
291e41f4b71Sopenharmony_ci        } else {
292e41f4b71Sopenharmony_ci            console.info(`callback: deleteKeyItem key success`);
293e41f4b71Sopenharmony_ci        }
294e41f4b71Sopenharmony_ci    });
295e41f4b71Sopenharmony_ci} catch (error) {
296e41f4b71Sopenharmony_ci    console.error(`callback: deleteKeyItem input arg invalid`);
297e41f4b71Sopenharmony_ci}
298e41f4b71Sopenharmony_ci```
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ci## huks.deleteKeyItem<sup>9+</sup>
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_cideleteKeyItem(keyAlias: string, options: HuksOptions) : Promise\<void>
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ciDeletes a key. This API uses a promise to return the result.
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci**Parameters**
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                               |
313e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ----------------------------------- |
314e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key to delete. It must be the key alias passed in when the key was generated.|
315e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Options for deleting the key. For example, you can pass in [HuksAuthStorageLevel](#huksauthstoragelevel11) to specify the security level of the key to delete. **HuksAuthStorageLevel** can be left empty, which means the default value **HUKS_AUTH_STORAGE_LEVEL_DE** is used.           |
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci**Return value**
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci| Type                                          | Description                                         |
320e41f4b71Sopenharmony_ci| ---------------------------------------------- | --------------------------------------------- |
321e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_ci**Error codes**
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ci| ID| Error Message     |
328e41f4b71Sopenharmony_ci| -------- | ------------- |
329e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
330e41f4b71Sopenharmony_ci| 801 | api is not supported. |
331e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
332e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
333e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
334e41f4b71Sopenharmony_ci| 12000012 | external error. |
335e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_ci**Example**
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci```ts
340e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
341e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
342e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
343e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
344e41f4b71Sopenharmony_ci    properties: []
345e41f4b71Sopenharmony_ci};
346e41f4b71Sopenharmony_citry {
347e41f4b71Sopenharmony_ci    huks.deleteKeyItem(keyAlias, emptyOptions)
348e41f4b71Sopenharmony_ci        .then ((data) => {
349e41f4b71Sopenharmony_ci            console.info(`promise: deleteKeyItem key success`);
350e41f4b71Sopenharmony_ci        })
351e41f4b71Sopenharmony_ci        .catch((error: Error) => {
352e41f4b71Sopenharmony_ci            console.error(`promise: deleteKeyItem failed`);
353e41f4b71Sopenharmony_ci        });
354e41f4b71Sopenharmony_ci} catch (error) {
355e41f4b71Sopenharmony_ci    console.error(`promise: deleteKeyItem input arg invalid`);
356e41f4b71Sopenharmony_ci}
357e41f4b71Sopenharmony_ci```
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci## huks.importKeyItem<sup>9+</sup>
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ciimportKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<void>) : void
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ciImports a key in plaintext. This API uses an asynchronous callback to return the result.
364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
368e41f4b71Sopenharmony_ci
369e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 9 to 11, and **SystemCapability.Security.Huks.Core** since API version 12.
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci**Parameters**
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                         |
374e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | --------------------------------------------- |
375e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key.                                   |
376e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Tags required for the import and key to import. The algorithm, key purpose, and key length are mandatory.|
377e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>        | Yes  | Callback used to return the result. If the operation is successful, no **err** value is returned; otherwise, an error code is returned.|
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_ci**Error codes**
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_ci| ID| Error Message     |
384e41f4b71Sopenharmony_ci| -------- | ------------- |
385e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
386e41f4b71Sopenharmony_ci| 801 | api is not supported. |
387e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
388e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
389e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
390e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
391e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
392e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
393e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
394e41f4b71Sopenharmony_ci| 12000012 | external error. |
395e41f4b71Sopenharmony_ci| 12000013 | queried credential does not exist. |
396e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
397e41f4b71Sopenharmony_ci| 12000015 | call service failed. |
398e41f4b71Sopenharmony_ci
399e41f4b71Sopenharmony_ci**Example**
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ci```ts
402e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
403e41f4b71Sopenharmony_ci/* Import a 256-bit AES key. */
404e41f4b71Sopenharmony_cilet plainTextSize32 = makeRandomArr(32);
405e41f4b71Sopenharmony_cifunction makeRandomArr(size: number) {
406e41f4b71Sopenharmony_ci    let arr = new Uint8Array(size);
407e41f4b71Sopenharmony_ci    for (let i = 0; i < size; i++) {
408e41f4b71Sopenharmony_ci        arr[i] = Math.floor(Math.random() * 10);
409e41f4b71Sopenharmony_ci    }
410e41f4b71Sopenharmony_ci    return arr;
411e41f4b71Sopenharmony_ci};
412e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
413e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = [
414e41f4b71Sopenharmony_ci    {
415e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
416e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_AES
417e41f4b71Sopenharmony_ci    },
418e41f4b71Sopenharmony_ci    {
419e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
420e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256
421e41f4b71Sopenharmony_ci    },
422e41f4b71Sopenharmony_ci    {
423e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
424e41f4b71Sopenharmony_ci        value:
425e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT
426e41f4b71Sopenharmony_ci    },
427e41f4b71Sopenharmony_ci    {
428e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PADDING,
429e41f4b71Sopenharmony_ci        value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7
430e41f4b71Sopenharmony_ci    },
431e41f4b71Sopenharmony_ci    {
432e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
433e41f4b71Sopenharmony_ci        value: huks.HuksCipherMode.HUKS_MODE_ECB
434e41f4b71Sopenharmony_ci    }
435e41f4b71Sopenharmony_ci];
436e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
437e41f4b71Sopenharmony_ci    properties: properties,
438e41f4b71Sopenharmony_ci    inData: plainTextSize32
439e41f4b71Sopenharmony_ci};
440e41f4b71Sopenharmony_citry {
441e41f4b71Sopenharmony_ci    huks.importKeyItem(keyAlias, options, (error, data) => {
442e41f4b71Sopenharmony_ci        if (error) {
443e41f4b71Sopenharmony_ci            console.error(`callback: importKeyItem failed`);
444e41f4b71Sopenharmony_ci        } else {
445e41f4b71Sopenharmony_ci            console.info(`callback: importKeyItem success`);
446e41f4b71Sopenharmony_ci        }
447e41f4b71Sopenharmony_ci    });
448e41f4b71Sopenharmony_ci} catch (error) {
449e41f4b71Sopenharmony_ci    console.error(`callback: importKeyItem input arg invalid`);
450e41f4b71Sopenharmony_ci}
451e41f4b71Sopenharmony_ci```
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci## huks.importKeyItem<sup>9+</sup>
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ciimportKeyItem(keyAlias: string, options: HuksOptions) : Promise\<void>
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ciImports a key in plaintext. This API uses a promise to return the result.
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
460e41f4b71Sopenharmony_ci
461e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ci**Parameters**
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                               |
466e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ----------------------------------- |
467e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key.                         |
468e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Tags required for the import and key to import. The algorithm, key purpose, and key length are mandatory.|
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci**Return value**
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ci| Type                                          | Description                                         |
473e41f4b71Sopenharmony_ci| ---------------------------------------------- | --------------------------------------------- |
474e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci**Error codes**
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ci| ID| Error Message     |
481e41f4b71Sopenharmony_ci| -------- | ------------- |
482e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
483e41f4b71Sopenharmony_ci| 801 | api is not supported. |
484e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
485e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
486e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
487e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
488e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
489e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
490e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
491e41f4b71Sopenharmony_ci| 12000012 | external error. |
492e41f4b71Sopenharmony_ci| 12000013 | queried credential does not exist. |
493e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
494e41f4b71Sopenharmony_ci| 12000015 | call service failed. |
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci**Example**
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci```ts
499e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
500e41f4b71Sopenharmony_ci/* Import an AES key of 128 bits. */
501e41f4b71Sopenharmony_cilet plainTextSize32 = makeRandomArr(32);
502e41f4b71Sopenharmony_cifunction makeRandomArr(size: number) {
503e41f4b71Sopenharmony_ci    let arr = new Uint8Array(size);
504e41f4b71Sopenharmony_ci    for (let i = 0; i < size; i++) {
505e41f4b71Sopenharmony_ci        arr[i] = Math.floor(Math.random() * 10);
506e41f4b71Sopenharmony_ci    }
507e41f4b71Sopenharmony_ci    return arr;
508e41f4b71Sopenharmony_ci};
509e41f4b71Sopenharmony_ci/* Step 1 Generate a key. */
510e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
511e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = [
512e41f4b71Sopenharmony_ci    {
513e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
514e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_AES
515e41f4b71Sopenharmony_ci    },
516e41f4b71Sopenharmony_ci    {
517e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
518e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256
519e41f4b71Sopenharmony_ci    },
520e41f4b71Sopenharmony_ci    {
521e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
522e41f4b71Sopenharmony_ci        value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT
523e41f4b71Sopenharmony_ci    },
524e41f4b71Sopenharmony_ci    {
525e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PADDING,
526e41f4b71Sopenharmony_ci        value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7
527e41f4b71Sopenharmony_ci    },
528e41f4b71Sopenharmony_ci    {
529e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
530e41f4b71Sopenharmony_ci        value: huks.HuksCipherMode.HUKS_MODE_ECB
531e41f4b71Sopenharmony_ci    }
532e41f4b71Sopenharmony_ci];
533e41f4b71Sopenharmony_cilet huksOptions: huks.HuksOptions = {
534e41f4b71Sopenharmony_ci    properties: properties,
535e41f4b71Sopenharmony_ci    inData: plainTextSize32
536e41f4b71Sopenharmony_ci};
537e41f4b71Sopenharmony_citry {
538e41f4b71Sopenharmony_ci    huks.importKeyItem(keyAlias, huksOptions)
539e41f4b71Sopenharmony_ci        .then((data) => {
540e41f4b71Sopenharmony_ci            console.info(`promise: importKeyItem success`);
541e41f4b71Sopenharmony_ci        })
542e41f4b71Sopenharmony_ci        .catch((error: Error) => {
543e41f4b71Sopenharmony_ci            console.error(`promise: importKeyItem failed`);
544e41f4b71Sopenharmony_ci        });
545e41f4b71Sopenharmony_ci} catch (error) {
546e41f4b71Sopenharmony_ci    console.error(`promise: importKeyItem input arg invalid`);
547e41f4b71Sopenharmony_ci}
548e41f4b71Sopenharmony_ci```
549e41f4b71Sopenharmony_ci
550e41f4b71Sopenharmony_ci## huks.attestKeyItem<sup>9+</sup>
551e41f4b71Sopenharmony_ci
552e41f4b71Sopenharmony_ciattestKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksReturnResult>) : void
553e41f4b71Sopenharmony_ci
554e41f4b71Sopenharmony_ciObtains the certificate used to attest a key. This API uses an asynchronous callback to return the result.
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ATTEST_KEY (available only for system applications)
557e41f4b71Sopenharmony_ci
558e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
559e41f4b71Sopenharmony_ci
560e41f4b71Sopenharmony_ci**Parameters**
561e41f4b71Sopenharmony_ci
562e41f4b71Sopenharmony_ci| Name  | Type                                                | Mandatory| Description                                         |
563e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | --------------------------------------------- |
564e41f4b71Sopenharmony_ci| keyAlias | string                                               | Yes  | Alias of the key. The certificate to be obtained stores the key.         |
565e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                          | Yes  | Parameters and data required for obtaining the certificate.           |
566e41f4b71Sopenharmony_ci| callback | AsyncCallback<[HuksReturnResult](#huksreturnresult9)> | Yes  | Callback used to return the result. If the operation is successful, no **err** value is returned; otherwise, an error code is returned.|
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_ci**Error codes**
569e41f4b71Sopenharmony_ci
570e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
571e41f4b71Sopenharmony_ci
572e41f4b71Sopenharmony_ci| ID| Error Message     |
573e41f4b71Sopenharmony_ci| -------- | ------------- |
574e41f4b71Sopenharmony_ci| 201 | check permission failed. |
575e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
576e41f4b71Sopenharmony_ci| 801 | api is not supported. |
577e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
578e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
579e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
580e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
581e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
582e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
583e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
584e41f4b71Sopenharmony_ci| 12000012 | external error. |
585e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_ci**Example**
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci```ts
590e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
591e41f4b71Sopenharmony_cilet securityLevel = stringToUint8Array('sec_level');
592e41f4b71Sopenharmony_cilet challenge = stringToUint8Array('challenge_data');
593e41f4b71Sopenharmony_cilet versionInfo = stringToUint8Array('version_info');
594e41f4b71Sopenharmony_cilet keyAliasString = "key attest";
595e41f4b71Sopenharmony_cifunction stringToUint8Array(str: string) {
596e41f4b71Sopenharmony_ci    let arr: number[] = [];
597e41f4b71Sopenharmony_ci    for (let i = 0, j = str.length; i < j; ++i) {
598e41f4b71Sopenharmony_ci        arr.push(str.charCodeAt(i));
599e41f4b71Sopenharmony_ci    }
600e41f4b71Sopenharmony_ci    let tmpUint8Array = new Uint8Array(arr);
601e41f4b71Sopenharmony_ci    return tmpUint8Array;
602e41f4b71Sopenharmony_ci}
603e41f4b71Sopenharmony_ci
604e41f4b71Sopenharmony_ciasync function generateKeyThenattestKey(alias: string) {
605e41f4b71Sopenharmony_ci    let aliasString = keyAliasString;
606e41f4b71Sopenharmony_ci    let aliasUint8 = stringToUint8Array(aliasString);
607e41f4b71Sopenharmony_ci    let generateProperties: Array<huks.HuksParam> = [
608e41f4b71Sopenharmony_ci        {
609e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
610e41f4b71Sopenharmony_ci            value: huks.HuksKeyAlg.HUKS_ALG_RSA
611e41f4b71Sopenharmony_ci        },
612e41f4b71Sopenharmony_ci        {
613e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
614e41f4b71Sopenharmony_ci            value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048
615e41f4b71Sopenharmony_ci        },
616e41f4b71Sopenharmony_ci        {
617e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PURPOSE,
618e41f4b71Sopenharmony_ci            value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY
619e41f4b71Sopenharmony_ci        },
620e41f4b71Sopenharmony_ci        {
621e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_DIGEST,
622e41f4b71Sopenharmony_ci            value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
623e41f4b71Sopenharmony_ci        },
624e41f4b71Sopenharmony_ci        {
625e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PADDING,
626e41f4b71Sopenharmony_ci            value: huks.HuksKeyPadding.HUKS_PADDING_PSS
627e41f4b71Sopenharmony_ci        },
628e41f4b71Sopenharmony_ci        {
629e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_GENERATE_TYPE,
630e41f4b71Sopenharmony_ci            value: huks.HuksKeyGenerateType.HUKS_KEY_GENERATE_TYPE_DEFAULT
631e41f4b71Sopenharmony_ci        },
632e41f4b71Sopenharmony_ci        {
633e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
634e41f4b71Sopenharmony_ci            value: huks.HuksCipherMode.HUKS_MODE_ECB
635e41f4b71Sopenharmony_ci        }
636e41f4b71Sopenharmony_ci    ];
637e41f4b71Sopenharmony_ci    let generateOptions: huks.HuksOptions = {
638e41f4b71Sopenharmony_ci        properties: generateProperties
639e41f4b71Sopenharmony_ci    };
640e41f4b71Sopenharmony_ci    let attestProperties: Array<huks.HuksParam> = [
641e41f4b71Sopenharmony_ci        {
642e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO,
643e41f4b71Sopenharmony_ci            value: securityLevel
644e41f4b71Sopenharmony_ci        },
645e41f4b71Sopenharmony_ci        {
646e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_CHALLENGE,
647e41f4b71Sopenharmony_ci            value: challenge
648e41f4b71Sopenharmony_ci        },
649e41f4b71Sopenharmony_ci        {
650e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_VERSION_INFO,
651e41f4b71Sopenharmony_ci            value: versionInfo
652e41f4b71Sopenharmony_ci        },
653e41f4b71Sopenharmony_ci        {
654e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_ALIAS,
655e41f4b71Sopenharmony_ci            value: aliasUint8
656e41f4b71Sopenharmony_ci        }
657e41f4b71Sopenharmony_ci    ];
658e41f4b71Sopenharmony_ci    let attestOptions: huks.HuksOptions = {
659e41f4b71Sopenharmony_ci        properties: attestProperties
660e41f4b71Sopenharmony_ci    };
661e41f4b71Sopenharmony_ci    try {
662e41f4b71Sopenharmony_ci        huks.generateKeyItem(alias, generateOptions, (error, data) => {
663e41f4b71Sopenharmony_ci            if (error) {
664e41f4b71Sopenharmony_ci                console.error(`callback: generateKeyItem failed`);
665e41f4b71Sopenharmony_ci            } else {
666e41f4b71Sopenharmony_ci                console.info(`callback: generateKeyItem success`);
667e41f4b71Sopenharmony_ci                try {
668e41f4b71Sopenharmony_ci                    huks.attestKeyItem(aliasString, attestOptions, (error, data) => {
669e41f4b71Sopenharmony_ci                        if (error) {
670e41f4b71Sopenharmony_ci                            console.error(`callback: attestKeyItem failed`);
671e41f4b71Sopenharmony_ci                        } else {
672e41f4b71Sopenharmony_ci                            console.info(`callback: attestKeyItem success`);
673e41f4b71Sopenharmony_ci                        }
674e41f4b71Sopenharmony_ci                    });
675e41f4b71Sopenharmony_ci                } catch (error) {
676e41f4b71Sopenharmony_ci                    console.error(`callback: attestKeyItem input arg invalid`);
677e41f4b71Sopenharmony_ci                }
678e41f4b71Sopenharmony_ci            }
679e41f4b71Sopenharmony_ci        });
680e41f4b71Sopenharmony_ci    } catch (error) {
681e41f4b71Sopenharmony_ci        console.error(`callback: generateKeyItem input arg invalid`);
682e41f4b71Sopenharmony_ci    }
683e41f4b71Sopenharmony_ci}
684e41f4b71Sopenharmony_ci```
685e41f4b71Sopenharmony_ci
686e41f4b71Sopenharmony_ci## huks.attestKeyItem<sup>9+</sup>
687e41f4b71Sopenharmony_ci
688e41f4b71Sopenharmony_ciattestKeyItem(keyAlias: string, options: HuksOptions) : Promise\<HuksReturnResult>
689e41f4b71Sopenharmony_ci
690e41f4b71Sopenharmony_ciObtains the certificate used to attest a key. This API uses a promise to return the result.
691e41f4b71Sopenharmony_ci
692e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ATTEST_KEY (available only for system applications)
693e41f4b71Sopenharmony_ci
694e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
695e41f4b71Sopenharmony_ci
696e41f4b71Sopenharmony_ci**Parameters**
697e41f4b71Sopenharmony_ci
698e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                |
699e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------------------ |
700e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key. The certificate to be obtained stores the key.|
701e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Parameters and data required for obtaining the certificate.  |
702e41f4b71Sopenharmony_ci
703e41f4b71Sopenharmony_ci**Return value**
704e41f4b71Sopenharmony_ci
705e41f4b71Sopenharmony_ci| Type                                          | Description                                         |
706e41f4b71Sopenharmony_ci| ---------------------------------------------- | --------------------------------------------- |
707e41f4b71Sopenharmony_ci| Promise<[HuksReturnResult](#huksreturnresult9)> | Promise used to return the result. If the operation is successful, **certChains** in **HuksReturnResult** is the certificate chain obtained.|
708e41f4b71Sopenharmony_ci
709e41f4b71Sopenharmony_ci**Error codes**
710e41f4b71Sopenharmony_ci
711e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ci| ID| Error Message     |
714e41f4b71Sopenharmony_ci| -------- | ------------- |
715e41f4b71Sopenharmony_ci| 201 | check permission failed. |
716e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
717e41f4b71Sopenharmony_ci| 801 | api is not supported. |
718e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
719e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
720e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
721e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
722e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
723e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
724e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
725e41f4b71Sopenharmony_ci| 12000012 | external error. |
726e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
727e41f4b71Sopenharmony_ci
728e41f4b71Sopenharmony_ci**Example**
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci```ts
731e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
732e41f4b71Sopenharmony_ci
733e41f4b71Sopenharmony_cilet securityLevel = stringToUint8Array('sec_level');
734e41f4b71Sopenharmony_cilet challenge = stringToUint8Array('challenge_data');
735e41f4b71Sopenharmony_cilet versionInfo = stringToUint8Array('version_info');
736e41f4b71Sopenharmony_cilet keyAliasString = "key attest";
737e41f4b71Sopenharmony_cifunction stringToUint8Array(str: string) {
738e41f4b71Sopenharmony_ci    let arr: number[] = [];
739e41f4b71Sopenharmony_ci    for (let i = 0, j = str.length; i < j; ++i) {
740e41f4b71Sopenharmony_ci        arr.push(str.charCodeAt(i));
741e41f4b71Sopenharmony_ci    }
742e41f4b71Sopenharmony_ci    let tmpUint8Array = new Uint8Array(arr);
743e41f4b71Sopenharmony_ci    return tmpUint8Array;
744e41f4b71Sopenharmony_ci}
745e41f4b71Sopenharmony_ciasync function generateKey(alias: string) {
746e41f4b71Sopenharmony_ci    let properties: Array<huks.HuksParam> = [
747e41f4b71Sopenharmony_ci        {
748e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
749e41f4b71Sopenharmony_ci            value: huks.HuksKeyAlg.HUKS_ALG_RSA
750e41f4b71Sopenharmony_ci        },
751e41f4b71Sopenharmony_ci        {
752e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
753e41f4b71Sopenharmony_ci            value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048
754e41f4b71Sopenharmony_ci        },
755e41f4b71Sopenharmony_ci        {
756e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PURPOSE,
757e41f4b71Sopenharmony_ci            value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY
758e41f4b71Sopenharmony_ci        },
759e41f4b71Sopenharmony_ci        {
760e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_DIGEST,
761e41f4b71Sopenharmony_ci            value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
762e41f4b71Sopenharmony_ci        },
763e41f4b71Sopenharmony_ci        {
764e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PADDING,
765e41f4b71Sopenharmony_ci            value: huks.HuksKeyPadding.HUKS_PADDING_PSS
766e41f4b71Sopenharmony_ci        },
767e41f4b71Sopenharmony_ci        {
768e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_GENERATE_TYPE,
769e41f4b71Sopenharmony_ci            value: huks.HuksKeyGenerateType.HUKS_KEY_GENERATE_TYPE_DEFAULT
770e41f4b71Sopenharmony_ci        },
771e41f4b71Sopenharmony_ci        {
772e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
773e41f4b71Sopenharmony_ci            value: huks.HuksCipherMode.HUKS_MODE_ECB
774e41f4b71Sopenharmony_ci        }
775e41f4b71Sopenharmony_ci    ];
776e41f4b71Sopenharmony_ci    let options: huks.HuksOptions = {
777e41f4b71Sopenharmony_ci        properties: properties
778e41f4b71Sopenharmony_ci    };
779e41f4b71Sopenharmony_ci    try {
780e41f4b71Sopenharmony_ci        await huks.generateKeyItem(alias, options)
781e41f4b71Sopenharmony_ci            .then((data) => {
782e41f4b71Sopenharmony_ci                console.info(`promise: generateKeyItem success`);
783e41f4b71Sopenharmony_ci            })
784e41f4b71Sopenharmony_ci            .catch((error: Error) => {
785e41f4b71Sopenharmony_ci                console.error(`promise: generateKeyItem failed`);
786e41f4b71Sopenharmony_ci            });
787e41f4b71Sopenharmony_ci    } catch (error) {
788e41f4b71Sopenharmony_ci        console.error(`promise: generateKeyItem input arg invalid`);
789e41f4b71Sopenharmony_ci    }
790e41f4b71Sopenharmony_ci}
791e41f4b71Sopenharmony_ciasync function attestKey() {
792e41f4b71Sopenharmony_ci    let aliasString = keyAliasString;
793e41f4b71Sopenharmony_ci    let aliasUint8 = stringToUint8Array(aliasString);
794e41f4b71Sopenharmony_ci    let properties: Array<huks.HuksParam> = [
795e41f4b71Sopenharmony_ci        {
796e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO,
797e41f4b71Sopenharmony_ci            value: securityLevel
798e41f4b71Sopenharmony_ci        },
799e41f4b71Sopenharmony_ci        {
800e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_CHALLENGE,
801e41f4b71Sopenharmony_ci            value: challenge
802e41f4b71Sopenharmony_ci        },
803e41f4b71Sopenharmony_ci        {
804e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_VERSION_INFO,
805e41f4b71Sopenharmony_ci            value: versionInfo
806e41f4b71Sopenharmony_ci        },
807e41f4b71Sopenharmony_ci        {
808e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_ALIAS,
809e41f4b71Sopenharmony_ci            value: aliasUint8
810e41f4b71Sopenharmony_ci        }
811e41f4b71Sopenharmony_ci    ];
812e41f4b71Sopenharmony_ci    let options: huks.HuksOptions = {
813e41f4b71Sopenharmony_ci        properties: properties
814e41f4b71Sopenharmony_ci    };
815e41f4b71Sopenharmony_ci    await generateKey(aliasString);
816e41f4b71Sopenharmony_ci    try {
817e41f4b71Sopenharmony_ci        await huks.attestKeyItem(aliasString, options)
818e41f4b71Sopenharmony_ci            .then((data) => {
819e41f4b71Sopenharmony_ci                console.info(`promise: attestKeyItem success`);
820e41f4b71Sopenharmony_ci            })
821e41f4b71Sopenharmony_ci            .catch((error: Error) => {
822e41f4b71Sopenharmony_ci                console.error(`promise: attestKeyItem failed`);
823e41f4b71Sopenharmony_ci            });
824e41f4b71Sopenharmony_ci    } catch (error) {
825e41f4b71Sopenharmony_ci        console.error(`promise: attestKeyItem input arg invalid`);
826e41f4b71Sopenharmony_ci    }
827e41f4b71Sopenharmony_ci}
828e41f4b71Sopenharmony_ci```
829e41f4b71Sopenharmony_ci
830e41f4b71Sopenharmony_ci## huks.anonAttestKeyItem<sup>11+</sup>
831e41f4b71Sopenharmony_ci
832e41f4b71Sopenharmony_cianonAttestKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksReturnResult>) : void
833e41f4b71Sopenharmony_ci
834e41f4b71Sopenharmony_ciObtains the certificate for anonymous attestation. This API uses an asynchronous callback to return the result.
835e41f4b71Sopenharmony_ci
836e41f4b71Sopenharmony_ciThis operation requires Internet access and takes time. If error code 12000012 is returned, the network is abnormal. If the device is not connected to the network, display a message, indicating that the network is not connected. If the network is connected, the failure may be caused by network jitter. Tray again later.
837e41f4b71Sopenharmony_ci
838e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
839e41f4b71Sopenharmony_ci
840e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
841e41f4b71Sopenharmony_ci
842e41f4b71Sopenharmony_ci**Parameters**
843e41f4b71Sopenharmony_ci
844e41f4b71Sopenharmony_ci| Name  | Type                                                | Mandatory| Description                                         |
845e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | --------------------------------------------- |
846e41f4b71Sopenharmony_ci| keyAlias | string                                               | Yes  | Alias of the key. The certificate to be obtained stores the key.         |
847e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                          | Yes  | Parameters and data required for obtaining the certificate.           |
848e41f4b71Sopenharmony_ci| callback | AsyncCallback<[HuksReturnResult](#huksreturnresult9)> | Yes  | Callback used to return the result. If the operation is successful, no **err** value is returned; otherwise, an error code is returned.|
849e41f4b71Sopenharmony_ci
850e41f4b71Sopenharmony_ci**Error codes**
851e41f4b71Sopenharmony_ci
852e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_ci| ID| Error Message     |
855e41f4b71Sopenharmony_ci| -------- | ------------- |
856e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
857e41f4b71Sopenharmony_ci| 801 | api is not supported. |
858e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
859e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
860e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
861e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
862e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
863e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
864e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
865e41f4b71Sopenharmony_ci| 12000012 | external error. |
866e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
867e41f4b71Sopenharmony_ci
868e41f4b71Sopenharmony_ci**Example**
869e41f4b71Sopenharmony_ci
870e41f4b71Sopenharmony_ci```ts
871e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
872e41f4b71Sopenharmony_cilet securityLevel = stringToUint8Array('sec_level');
873e41f4b71Sopenharmony_cilet challenge = stringToUint8Array('challenge_data');
874e41f4b71Sopenharmony_cilet versionInfo = stringToUint8Array('version_info');
875e41f4b71Sopenharmony_cilet keyAliasString = "key anon attest";
876e41f4b71Sopenharmony_cifunction stringToUint8Array(str: string): Uint8Array {
877e41f4b71Sopenharmony_ci    let arr: number[] = [];
878e41f4b71Sopenharmony_ci    for (let i = 0, j = str.length; i < j; ++i) {
879e41f4b71Sopenharmony_ci        arr.push(str.charCodeAt(i));
880e41f4b71Sopenharmony_ci    }
881e41f4b71Sopenharmony_ci    let tmpUint8Array = new Uint8Array(arr);
882e41f4b71Sopenharmony_ci    return tmpUint8Array;
883e41f4b71Sopenharmony_ci}
884e41f4b71Sopenharmony_ci
885e41f4b71Sopenharmony_ciasync function generateKeyThenAttestKey(alias: string): Promise<void> {
886e41f4b71Sopenharmony_ci    let aliasString = keyAliasString;
887e41f4b71Sopenharmony_ci    let aliasUint8 = stringToUint8Array(aliasString);
888e41f4b71Sopenharmony_ci    let generateProperties: Array<huks.HuksParam> = [
889e41f4b71Sopenharmony_ci        {
890e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
891e41f4b71Sopenharmony_ci            value: huks.HuksKeyAlg.HUKS_ALG_RSA
892e41f4b71Sopenharmony_ci        },
893e41f4b71Sopenharmony_ci        {
894e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
895e41f4b71Sopenharmony_ci            value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048
896e41f4b71Sopenharmony_ci        },
897e41f4b71Sopenharmony_ci        {
898e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PURPOSE,
899e41f4b71Sopenharmony_ci            value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY
900e41f4b71Sopenharmony_ci        },
901e41f4b71Sopenharmony_ci        {
902e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_DIGEST,
903e41f4b71Sopenharmony_ci            value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
904e41f4b71Sopenharmony_ci        },
905e41f4b71Sopenharmony_ci        {
906e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PADDING,
907e41f4b71Sopenharmony_ci            value: huks.HuksKeyPadding.HUKS_PADDING_PSS
908e41f4b71Sopenharmony_ci        },
909e41f4b71Sopenharmony_ci        {
910e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_GENERATE_TYPE,
911e41f4b71Sopenharmony_ci            value: huks.HuksKeyGenerateType.HUKS_KEY_GENERATE_TYPE_DEFAULT
912e41f4b71Sopenharmony_ci        },
913e41f4b71Sopenharmony_ci        {
914e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
915e41f4b71Sopenharmony_ci            value: huks.HuksCipherMode.HUKS_MODE_ECB
916e41f4b71Sopenharmony_ci        }
917e41f4b71Sopenharmony_ci    ];
918e41f4b71Sopenharmony_ci    let generateOptions: huks.HuksOptions = {
919e41f4b71Sopenharmony_ci        properties: generateProperties
920e41f4b71Sopenharmony_ci    };
921e41f4b71Sopenharmony_ci    let anonAttestProperties: Array<huks.HuksParam> = [
922e41f4b71Sopenharmony_ci        {
923e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO,
924e41f4b71Sopenharmony_ci            value: securityLevel
925e41f4b71Sopenharmony_ci        },
926e41f4b71Sopenharmony_ci        {
927e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_CHALLENGE,
928e41f4b71Sopenharmony_ci            value: challenge
929e41f4b71Sopenharmony_ci        },
930e41f4b71Sopenharmony_ci        {
931e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_VERSION_INFO,
932e41f4b71Sopenharmony_ci            value: versionInfo
933e41f4b71Sopenharmony_ci        },
934e41f4b71Sopenharmony_ci        {
935e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_ALIAS,
936e41f4b71Sopenharmony_ci            value: aliasUint8
937e41f4b71Sopenharmony_ci        }
938e41f4b71Sopenharmony_ci    ];
939e41f4b71Sopenharmony_ci    let anonAttestOptions: huks.HuksOptions = {
940e41f4b71Sopenharmony_ci        properties: anonAttestProperties
941e41f4b71Sopenharmony_ci    };
942e41f4b71Sopenharmony_ci    try {
943e41f4b71Sopenharmony_ci        huks.generateKeyItem(alias, generateOptions, (error, data) => {
944e41f4b71Sopenharmony_ci            if (error) {
945e41f4b71Sopenharmony_ci                console.error(`callback: generateKeyItem failed`);
946e41f4b71Sopenharmony_ci            } else {
947e41f4b71Sopenharmony_ci                console.info(`callback: generateKeyItem success`);
948e41f4b71Sopenharmony_ci                try {
949e41f4b71Sopenharmony_ci                    huks.anonAttestKeyItem(aliasString, anonAttestOptions, (error, data) => {
950e41f4b71Sopenharmony_ci                        if (error) {
951e41f4b71Sopenharmony_ci                            console.error(`callback: anonAttestKeyItem failed`);
952e41f4b71Sopenharmony_ci                        } else {
953e41f4b71Sopenharmony_ci                            console.info(`callback: anonAttestKeyItem success`);
954e41f4b71Sopenharmony_ci                        }
955e41f4b71Sopenharmony_ci                    });
956e41f4b71Sopenharmony_ci                } catch (error) {
957e41f4b71Sopenharmony_ci                    console.error(`callback: anonAttestKeyItem input arg invalid`);
958e41f4b71Sopenharmony_ci                }
959e41f4b71Sopenharmony_ci            }
960e41f4b71Sopenharmony_ci        });
961e41f4b71Sopenharmony_ci    } catch (error) {
962e41f4b71Sopenharmony_ci        console.error(`callback: generateKeyItem input arg invalid`);
963e41f4b71Sopenharmony_ci    }
964e41f4b71Sopenharmony_ci}
965e41f4b71Sopenharmony_ci```
966e41f4b71Sopenharmony_ci
967e41f4b71Sopenharmony_ci## huks.anonAttestKeyItem<sup>11+</sup>
968e41f4b71Sopenharmony_ci
969e41f4b71Sopenharmony_cianonAttestKeyItem(keyAlias: string, options: HuksOptions) : Promise\<HuksReturnResult>
970e41f4b71Sopenharmony_ci
971e41f4b71Sopenharmony_ciObtains the certificate for anonymous attestation. This API uses a promise to return the result.
972e41f4b71Sopenharmony_ci
973e41f4b71Sopenharmony_ciThis operation requires Internet access and takes time. If error code 12000012 is returned, the network is abnormal. If the device is not connected to the network, display a message, indicating that the network is not connected. If the network is connected, the failure may be caused by network jitter. Tray again later.
974e41f4b71Sopenharmony_ci
975e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
976e41f4b71Sopenharmony_ci
977e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
978e41f4b71Sopenharmony_ci
979e41f4b71Sopenharmony_ci**Parameters**
980e41f4b71Sopenharmony_ci
981e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                |
982e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------------------ |
983e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key. The certificate to be obtained stores the key.|
984e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Parameters and data required for obtaining the certificate.  |
985e41f4b71Sopenharmony_ci
986e41f4b71Sopenharmony_ci**Return value**
987e41f4b71Sopenharmony_ci
988e41f4b71Sopenharmony_ci| Type                                          | Description                                         |
989e41f4b71Sopenharmony_ci| ---------------------------------------------- | --------------------------------------------- |
990e41f4b71Sopenharmony_ci| Promise<[HuksReturnResult](#huksreturnresult9)> | Promise used to return the result. If the operation is successful, **certChains** in **HuksReturnResult** is the certificate chain obtained.|
991e41f4b71Sopenharmony_ci
992e41f4b71Sopenharmony_ci**Error codes**
993e41f4b71Sopenharmony_ci
994e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
995e41f4b71Sopenharmony_ci
996e41f4b71Sopenharmony_ci| ID| Error Message     |
997e41f4b71Sopenharmony_ci| -------- | ------------- |
998e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
999e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1000e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
1001e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1002e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1003e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1004e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1005e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1006e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1007e41f4b71Sopenharmony_ci| 12000012 | external error. |
1008e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1009e41f4b71Sopenharmony_ci
1010e41f4b71Sopenharmony_ci**Example**
1011e41f4b71Sopenharmony_ci
1012e41f4b71Sopenharmony_ci```ts
1013e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1014e41f4b71Sopenharmony_ci
1015e41f4b71Sopenharmony_cilet securityLevel = stringToUint8Array('sec_level');
1016e41f4b71Sopenharmony_cilet challenge = stringToUint8Array('challenge_data');
1017e41f4b71Sopenharmony_cilet versionInfo = stringToUint8Array('version_info');
1018e41f4b71Sopenharmony_cilet keyAliasString = "key anon attest";
1019e41f4b71Sopenharmony_cifunction stringToUint8Array(str: string): Uint8Array {
1020e41f4b71Sopenharmony_ci    let arr: number[] = [];
1021e41f4b71Sopenharmony_ci    for (let i = 0, j = str.length; i < j; ++i) {
1022e41f4b71Sopenharmony_ci        arr.push(str.charCodeAt(i));
1023e41f4b71Sopenharmony_ci    }
1024e41f4b71Sopenharmony_ci    let tmpUint8Array = new Uint8Array(arr);
1025e41f4b71Sopenharmony_ci    return tmpUint8Array;
1026e41f4b71Sopenharmony_ci}
1027e41f4b71Sopenharmony_ciasync function generateKey(alias: string): Promise<void> {
1028e41f4b71Sopenharmony_ci    let properties: Array<huks.HuksParam> = [
1029e41f4b71Sopenharmony_ci        {
1030e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
1031e41f4b71Sopenharmony_ci            value: huks.HuksKeyAlg.HUKS_ALG_RSA
1032e41f4b71Sopenharmony_ci        },
1033e41f4b71Sopenharmony_ci        {
1034e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
1035e41f4b71Sopenharmony_ci            value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048
1036e41f4b71Sopenharmony_ci        },
1037e41f4b71Sopenharmony_ci        {
1038e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PURPOSE,
1039e41f4b71Sopenharmony_ci            value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY
1040e41f4b71Sopenharmony_ci        },
1041e41f4b71Sopenharmony_ci        {
1042e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_DIGEST,
1043e41f4b71Sopenharmony_ci            value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
1044e41f4b71Sopenharmony_ci        },
1045e41f4b71Sopenharmony_ci        {
1046e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PADDING,
1047e41f4b71Sopenharmony_ci            value: huks.HuksKeyPadding.HUKS_PADDING_PSS
1048e41f4b71Sopenharmony_ci        },
1049e41f4b71Sopenharmony_ci        {
1050e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_GENERATE_TYPE,
1051e41f4b71Sopenharmony_ci            value: huks.HuksKeyGenerateType.HUKS_KEY_GENERATE_TYPE_DEFAULT
1052e41f4b71Sopenharmony_ci        },
1053e41f4b71Sopenharmony_ci        {
1054e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
1055e41f4b71Sopenharmony_ci            value: huks.HuksCipherMode.HUKS_MODE_ECB
1056e41f4b71Sopenharmony_ci        }
1057e41f4b71Sopenharmony_ci    ];
1058e41f4b71Sopenharmony_ci    let options: huks.HuksOptions = {
1059e41f4b71Sopenharmony_ci        properties: properties
1060e41f4b71Sopenharmony_ci    };
1061e41f4b71Sopenharmony_ci    try {
1062e41f4b71Sopenharmony_ci        let data = await huks.generateKeyItem(alias, options);
1063e41f4b71Sopenharmony_ci    } catch (error) {
1064e41f4b71Sopenharmony_ci        console.error(`promise: generateKeyItem failed`);
1065e41f4b71Sopenharmony_ci    }
1066e41f4b71Sopenharmony_ci}
1067e41f4b71Sopenharmony_ciasync function anonAttestKey(): Promise<void> {
1068e41f4b71Sopenharmony_ci    let aliasString = keyAliasString;
1069e41f4b71Sopenharmony_ci    let aliasUint8 = stringToUint8Array(aliasString);
1070e41f4b71Sopenharmony_ci    let properties: Array<huks.HuksParam> = [
1071e41f4b71Sopenharmony_ci        {
1072e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO,
1073e41f4b71Sopenharmony_ci            value: securityLevel
1074e41f4b71Sopenharmony_ci        },
1075e41f4b71Sopenharmony_ci        {
1076e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_CHALLENGE,
1077e41f4b71Sopenharmony_ci            value: challenge
1078e41f4b71Sopenharmony_ci        },
1079e41f4b71Sopenharmony_ci        {
1080e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_VERSION_INFO,
1081e41f4b71Sopenharmony_ci            value: versionInfo
1082e41f4b71Sopenharmony_ci        },
1083e41f4b71Sopenharmony_ci        {
1084e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_ALIAS,
1085e41f4b71Sopenharmony_ci            value: aliasUint8
1086e41f4b71Sopenharmony_ci        }
1087e41f4b71Sopenharmony_ci    ];
1088e41f4b71Sopenharmony_ci    let options: huks.HuksOptions = {
1089e41f4b71Sopenharmony_ci        properties: properties
1090e41f4b71Sopenharmony_ci    };
1091e41f4b71Sopenharmony_ci    await generateKey(aliasString);
1092e41f4b71Sopenharmony_ci    try {
1093e41f4b71Sopenharmony_ci        let data = await huks.anonAttestKeyItem(aliasString, options);
1094e41f4b71Sopenharmony_ci    } catch (error) {
1095e41f4b71Sopenharmony_ci        console.error(`promise: anonAttestKeyItem fail`);
1096e41f4b71Sopenharmony_ci    }
1097e41f4b71Sopenharmony_ci}
1098e41f4b71Sopenharmony_ci```
1099e41f4b71Sopenharmony_ci
1100e41f4b71Sopenharmony_ci## huks.importWrappedKeyItem<sup>9+</sup>
1101e41f4b71Sopenharmony_ci
1102e41f4b71Sopenharmony_ciimportWrappedKeyItem(keyAlias: string, wrappingKeyAlias: string, options: HuksOptions, callback: AsyncCallback\<void>) : void
1103e41f4b71Sopenharmony_ci
1104e41f4b71Sopenharmony_ciImports a wrapped key. This API uses an asynchronous callback to return the result.
1105e41f4b71Sopenharmony_ci
1106e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1107e41f4b71Sopenharmony_ci
1108e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
1109e41f4b71Sopenharmony_ci
1110e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 9 to 11, and **SystemCapability.Security.Huks.Core** since API version 12.
1111e41f4b71Sopenharmony_ci
1112e41f4b71Sopenharmony_ci**Parameters**
1113e41f4b71Sopenharmony_ci
1114e41f4b71Sopenharmony_ci| Name          | Type                       | Mandatory| Description                                         |
1115e41f4b71Sopenharmony_ci| ---------------- | --------------------------- | ---- | --------------------------------------------- |
1116e41f4b71Sopenharmony_ci| keyAlias         | string                      | Yes  | Alias of the wrapped key to import.             |
1117e41f4b71Sopenharmony_ci| wrappingKeyAlias | string                      | Yes  | Alias of the data used to unwrap the key imported.   |
1118e41f4b71Sopenharmony_ci| options          | [HuksOptions](#huksoptions) | Yes  | Tags required for the import and the wrapped key to import. The algorithm, key purpose, and key length are mandatory.|
1119e41f4b71Sopenharmony_ci| callback         | AsyncCallback\<void>        | Yes  | Callback used to return the result. If the operation is successful, no **err** value is returned; otherwise, an error code is returned.|
1120e41f4b71Sopenharmony_ci
1121e41f4b71Sopenharmony_ci**Error codes**
1122e41f4b71Sopenharmony_ci
1123e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1124e41f4b71Sopenharmony_ci
1125e41f4b71Sopenharmony_ci| ID| Error Message     |
1126e41f4b71Sopenharmony_ci| -------- | ------------- |
1127e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1128e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1129e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
1130e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1131e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1132e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1133e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1134e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1135e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1136e41f4b71Sopenharmony_ci| 12000012 | external error. |
1137e41f4b71Sopenharmony_ci| 12000013 | queried credential does not exist. |
1138e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1139e41f4b71Sopenharmony_ci| 12000015 | call service failed. |
1140e41f4b71Sopenharmony_ci
1141e41f4b71Sopenharmony_ci**Example**
1142e41f4b71Sopenharmony_ci
1143e41f4b71Sopenharmony_ci```ts
1144e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1145e41f4b71Sopenharmony_ci
1146e41f4b71Sopenharmony_cilet alias1 = "importAlias";
1147e41f4b71Sopenharmony_cilet alias2 = "wrappingKeyAlias";
1148e41f4b71Sopenharmony_ciasync function TestGenFunc(alias: string, options: huks.HuksOptions) {
1149e41f4b71Sopenharmony_ci    try {
1150e41f4b71Sopenharmony_ci        await genKey(alias, options)
1151e41f4b71Sopenharmony_ci            .then((data) => {
1152e41f4b71Sopenharmony_ci                console.info(`callback: generateKeyItem success`);
1153e41f4b71Sopenharmony_ci            })
1154e41f4b71Sopenharmony_ci            .catch((error: Error) => {
1155e41f4b71Sopenharmony_ci                console.error(`callback: generateKeyItem failed`);
1156e41f4b71Sopenharmony_ci            });
1157e41f4b71Sopenharmony_ci    } catch (error) {
1158e41f4b71Sopenharmony_ci        console.error(`callback: generateKeyItem input arg invalid`);
1159e41f4b71Sopenharmony_ci    }
1160e41f4b71Sopenharmony_ci}
1161e41f4b71Sopenharmony_cifunction genKey(alias: string, options: huks.HuksOptions) {
1162e41f4b71Sopenharmony_ci    return new Promise<void>((resolve, reject) => {
1163e41f4b71Sopenharmony_ci        try {
1164e41f4b71Sopenharmony_ci            huks.generateKeyItem(alias, options, (error, data) => {
1165e41f4b71Sopenharmony_ci                if (error) {
1166e41f4b71Sopenharmony_ci                    reject(error);
1167e41f4b71Sopenharmony_ci                } else {
1168e41f4b71Sopenharmony_ci                    resolve(data);
1169e41f4b71Sopenharmony_ci                }
1170e41f4b71Sopenharmony_ci            });
1171e41f4b71Sopenharmony_ci        } catch (error) {
1172e41f4b71Sopenharmony_ci            throw (new Error(error));
1173e41f4b71Sopenharmony_ci        }
1174e41f4b71Sopenharmony_ci    });
1175e41f4b71Sopenharmony_ci}
1176e41f4b71Sopenharmony_ciasync function TestExportFunc(alias: string, options: huks.HuksOptions) {
1177e41f4b71Sopenharmony_ci    try {
1178e41f4b71Sopenharmony_ci        await exportKey(alias, options)
1179e41f4b71Sopenharmony_ci            .then((data) => {
1180e41f4b71Sopenharmony_ci                console.info(`callback: exportKeyItem success, data = ${JSON.stringify(data)}`);
1181e41f4b71Sopenharmony_ci            })
1182e41f4b71Sopenharmony_ci            .catch((error: Error) => {
1183e41f4b71Sopenharmony_ci                console.error(`callback: exportKeyItem failed`);
1184e41f4b71Sopenharmony_ci            });
1185e41f4b71Sopenharmony_ci    } catch (error) {
1186e41f4b71Sopenharmony_ci        console.error(`callback: exportKeyItem input arg invalid`);
1187e41f4b71Sopenharmony_ci    }
1188e41f4b71Sopenharmony_ci}
1189e41f4b71Sopenharmony_cifunction exportKey(alias: string, options: huks.HuksOptions) {
1190e41f4b71Sopenharmony_ci    return new Promise<huks.HuksReturnResult>((resolve, reject) => {
1191e41f4b71Sopenharmony_ci        try {
1192e41f4b71Sopenharmony_ci            huks.exportKeyItem(alias, options, (error, data) => {
1193e41f4b71Sopenharmony_ci                if (error) {
1194e41f4b71Sopenharmony_ci                    reject(error);
1195e41f4b71Sopenharmony_ci                } else {
1196e41f4b71Sopenharmony_ci                    resolve(data);
1197e41f4b71Sopenharmony_ci                }
1198e41f4b71Sopenharmony_ci            });
1199e41f4b71Sopenharmony_ci        } catch (error) {
1200e41f4b71Sopenharmony_ci            throw (new Error(error));
1201e41f4b71Sopenharmony_ci        }
1202e41f4b71Sopenharmony_ci    });
1203e41f4b71Sopenharmony_ci}
1204e41f4b71Sopenharmony_ciasync function TestImportWrappedFunc(alias: string, wrappingAlias: string, options: huks.HuksOptions) {
1205e41f4b71Sopenharmony_ci    try {
1206e41f4b71Sopenharmony_ci        await importWrappedKey(alias, wrappingAlias, options)
1207e41f4b71Sopenharmony_ci            .then((data) => {
1208e41f4b71Sopenharmony_ci                console.info(`callback: importWrappedKeyItem success`);
1209e41f4b71Sopenharmony_ci            })
1210e41f4b71Sopenharmony_ci            .catch((error: Error) => {
1211e41f4b71Sopenharmony_ci                console.error(`callback: importWrappedKeyItem failed`);
1212e41f4b71Sopenharmony_ci            });
1213e41f4b71Sopenharmony_ci    } catch (error) {
1214e41f4b71Sopenharmony_ci        console.error(`callback: importWrappedKeyItem input arg invalid`);
1215e41f4b71Sopenharmony_ci    }
1216e41f4b71Sopenharmony_ci}
1217e41f4b71Sopenharmony_cifunction importWrappedKey(alias: string, wrappingAlias: string, options: huks.HuksOptions) {
1218e41f4b71Sopenharmony_ci    return new Promise<void>((resolve, reject) => {
1219e41f4b71Sopenharmony_ci        try {
1220e41f4b71Sopenharmony_ci            huks.importWrappedKeyItem(alias, wrappingAlias, options, (error, data) => {
1221e41f4b71Sopenharmony_ci                if (error) {
1222e41f4b71Sopenharmony_ci                    reject(error);
1223e41f4b71Sopenharmony_ci                } else {
1224e41f4b71Sopenharmony_ci                    resolve(data);
1225e41f4b71Sopenharmony_ci                }
1226e41f4b71Sopenharmony_ci            });
1227e41f4b71Sopenharmony_ci        } catch (error) {
1228e41f4b71Sopenharmony_ci            throw (new Error(error));
1229e41f4b71Sopenharmony_ci        }
1230e41f4b71Sopenharmony_ci    });
1231e41f4b71Sopenharmony_ci}
1232e41f4b71Sopenharmony_ciasync function TestImportWrappedKeyFunc(
1233e41f4b71Sopenharmony_ci        alias: string,
1234e41f4b71Sopenharmony_ci        wrappingAlias: string,
1235e41f4b71Sopenharmony_ci        genOptions: huks.HuksOptions,
1236e41f4b71Sopenharmony_ci        importOptions: huks.HuksOptions
1237e41f4b71Sopenharmony_ci) {
1238e41f4b71Sopenharmony_ci    await TestGenFunc(wrappingAlias, genOptions);
1239e41f4b71Sopenharmony_ci    await TestExportFunc(wrappingAlias, genOptions);
1240e41f4b71Sopenharmony_ci
1241e41f4b71Sopenharmony_ci    /*The following operations do not invoke the HUKS APIs, and the specific implementation is not provided here.
1242e41f4b71Sopenharmony_ci     * For example, import **keyA**.
1243e41f4b71Sopenharmony_ci     * 1. Use ECC to generate a public and private key pair **keyB**. The public key is **keyB_pub**, and the private key is **keyB_pri**.
1244e41f4b71Sopenharmony_ci     * 2. Use **keyB_pri** and the public key obtained from **wrappingAlias** to negotiate the shared key **share_key**.
1245e41f4b71Sopenharmony_ci     * 3. Randomly generate a key **kek** and use it to encrypt **keyA** with AES-GCM. During the encryption, record **nonce1**, **aad1**, ciphertext **keyA_enc**, and encrypted **tag1**.
1246e41f4b71Sopenharmony_ci     * 4. Use **share_key** to encrypt **kek** with AES-GCM. During the encryption, record **nonce2**, **aad2**, ciphertext **kek_enc**, and encrypted **tag2**.
1247e41f4b71Sopenharmony_ci     * 5. Generate the **importOptions.inData** field in the following format:
1248e41f4b71Sopenharmony_ci     * keyB_pub length (4 bytes) + keyB_pub + aad2 length (4 bytes) + aad2 +
1249e41f4b71Sopenharmony_ci     * nonce2 length (4 bytes) + nonce2 + tag2 length (4 bytes) + tag2 +
1250e41f4b71Sopenharmony_ci     * kek_enc length (4 bytes) + kek_enc + aad1 length (4 bytes) + aad1 +
1251e41f4b71Sopenharmony_ci     * nonce1 length (4 bytes) + nonce1 + tag1 length (4 bytes) + tag1 +
1252e41f4b71Sopenharmony_ci     * Memory occupied by the keyA length (4 bytes) + keyA length + keyA_enc length (4 bytes) + keyA_enc
1253e41f4b71Sopenharmony_ci     */
1254e41f4b71Sopenharmony_ci    /* The key data imported may be different from the sample code given below. The data structure is described in the preceding comments. */
1255e41f4b71Sopenharmony_ci    let inputKey = new Uint8Array([0x02, 0x00, 0x00, 0x00]);
1256e41f4b71Sopenharmony_ci    importOptions.inData = inputKey;
1257e41f4b71Sopenharmony_ci    await TestImportWrappedFunc(alias, wrappingAlias, importOptions);
1258e41f4b71Sopenharmony_ci}
1259e41f4b71Sopenharmony_cifunction makeGenerateOptions() {
1260e41f4b71Sopenharmony_ci    let properties: Array<huks.HuksParam> = [
1261e41f4b71Sopenharmony_ci        {
1262e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
1263e41f4b71Sopenharmony_ci            value: huks.HuksKeyAlg.HUKS_ALG_ECC
1264e41f4b71Sopenharmony_ci        },
1265e41f4b71Sopenharmony_ci        {
1266e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
1267e41f4b71Sopenharmony_ci            value: huks.HuksKeySize.HUKS_ECC_KEY_SIZE_256
1268e41f4b71Sopenharmony_ci        },
1269e41f4b71Sopenharmony_ci        {
1270e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PURPOSE,
1271e41f4b71Sopenharmony_ci            value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_UNWRAP
1272e41f4b71Sopenharmony_ci        },
1273e41f4b71Sopenharmony_ci        {
1274e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_DIGEST,
1275e41f4b71Sopenharmony_ci            value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
1276e41f4b71Sopenharmony_ci        },
1277e41f4b71Sopenharmony_ci        {
1278e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE,
1279e41f4b71Sopenharmony_ci            value: huks.HuksImportKeyType.HUKS_KEY_TYPE_KEY_PAIR,
1280e41f4b71Sopenharmony_ci        }
1281e41f4b71Sopenharmony_ci    ];
1282e41f4b71Sopenharmony_ci    let options: huks.HuksOptions = {
1283e41f4b71Sopenharmony_ci        properties: properties
1284e41f4b71Sopenharmony_ci    };
1285e41f4b71Sopenharmony_ci    return options;
1286e41f4b71Sopenharmony_ci};
1287e41f4b71Sopenharmony_cifunction makeImportOptions() {
1288e41f4b71Sopenharmony_ci    let properties: Array<huks.HuksParam> = [
1289e41f4b71Sopenharmony_ci        {
1290e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
1291e41f4b71Sopenharmony_ci            value: huks.HuksKeyAlg.HUKS_ALG_AES
1292e41f4b71Sopenharmony_ci        },
1293e41f4b71Sopenharmony_ci        {
1294e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
1295e41f4b71Sopenharmony_ci            value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256
1296e41f4b71Sopenharmony_ci        },
1297e41f4b71Sopenharmony_ci        {
1298e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PURPOSE,
1299e41f4b71Sopenharmony_ci            value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT
1300e41f4b71Sopenharmony_ci        },
1301e41f4b71Sopenharmony_ci        {
1302e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
1303e41f4b71Sopenharmony_ci            value: huks.HuksCipherMode.HUKS_MODE_CBC
1304e41f4b71Sopenharmony_ci        },
1305e41f4b71Sopenharmony_ci        {
1306e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_PADDING,
1307e41f4b71Sopenharmony_ci            value: huks.HuksKeyPadding.HUKS_PADDING_NONE
1308e41f4b71Sopenharmony_ci        },
1309e41f4b71Sopenharmony_ci        {
1310e41f4b71Sopenharmony_ci            tag: huks.HuksTag.HUKS_TAG_UNWRAP_ALGORITHM_SUITE,
1311e41f4b71Sopenharmony_ci            value: huks.HuksUnwrapSuite.HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING
1312e41f4b71Sopenharmony_ci        }
1313e41f4b71Sopenharmony_ci    ];
1314e41f4b71Sopenharmony_ci    let options: huks.HuksOptions = {
1315e41f4b71Sopenharmony_ci        properties: properties
1316e41f4b71Sopenharmony_ci    };
1317e41f4b71Sopenharmony_ci    return options;
1318e41f4b71Sopenharmony_ci};
1319e41f4b71Sopenharmony_cifunction huksImportWrappedKey() {
1320e41f4b71Sopenharmony_ci    let genOptions = makeGenerateOptions();
1321e41f4b71Sopenharmony_ci    let importOptions = makeImportOptions();
1322e41f4b71Sopenharmony_ci    TestImportWrappedKeyFunc(
1323e41f4b71Sopenharmony_ci        alias1,
1324e41f4b71Sopenharmony_ci        alias2,
1325e41f4b71Sopenharmony_ci        genOptions,
1326e41f4b71Sopenharmony_ci        importOptions
1327e41f4b71Sopenharmony_ci    );
1328e41f4b71Sopenharmony_ci}
1329e41f4b71Sopenharmony_ci```
1330e41f4b71Sopenharmony_ci
1331e41f4b71Sopenharmony_ci## huks.importWrappedKeyItem<sup>9+</sup>
1332e41f4b71Sopenharmony_ci
1333e41f4b71Sopenharmony_ciimportWrappedKeyItem(keyAlias: string, wrappingKeyAlias: string, options: HuksOptions) : Promise\<void>
1334e41f4b71Sopenharmony_ci
1335e41f4b71Sopenharmony_ciImports a wrapped key. This API uses a promise to return the result.
1336e41f4b71Sopenharmony_ci
1337e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1338e41f4b71Sopenharmony_ci
1339e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
1340e41f4b71Sopenharmony_ci
1341e41f4b71Sopenharmony_ci**Parameters**
1342e41f4b71Sopenharmony_ci
1343e41f4b71Sopenharmony_ci| Name          | Type                       | Mandatory| Description                                         |
1344e41f4b71Sopenharmony_ci| ---------------- | --------------------------- | ---- | --------------------------------------------- |
1345e41f4b71Sopenharmony_ci| keyAlias         | string                      | Yes  | Alias of the wrapped key to import.             |
1346e41f4b71Sopenharmony_ci| wrappingKeyAlias | string                      | Yes  | Alias of the data used to unwrap the key imported.   |
1347e41f4b71Sopenharmony_ci| options          | [HuksOptions](#huksoptions) | Yes  | Tags required for the import and the wrapped key to import. The algorithm, key purpose, and key length are mandatory.|
1348e41f4b71Sopenharmony_ci
1349e41f4b71Sopenharmony_ci**Return value**
1350e41f4b71Sopenharmony_ci
1351e41f4b71Sopenharmony_ci| Type                                          | Description                                         |
1352e41f4b71Sopenharmony_ci| ---------------------------------------------- | --------------------------------------------- |
1353e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
1354e41f4b71Sopenharmony_ci
1355e41f4b71Sopenharmony_ci**Error codes**
1356e41f4b71Sopenharmony_ci
1357e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1358e41f4b71Sopenharmony_ci
1359e41f4b71Sopenharmony_ci| ID| Error Message     |
1360e41f4b71Sopenharmony_ci| -------- | ------------- |
1361e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1362e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1363e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
1364e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1365e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1366e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1367e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1368e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1369e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1370e41f4b71Sopenharmony_ci| 12000012 | external error. |
1371e41f4b71Sopenharmony_ci| 12000013 | queried credential does not exist. |
1372e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1373e41f4b71Sopenharmony_ci| 12000015 | call service failed. |
1374e41f4b71Sopenharmony_ci
1375e41f4b71Sopenharmony_ci**Example**
1376e41f4b71Sopenharmony_ci
1377e41f4b71Sopenharmony_ci```ts
1378e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1379e41f4b71Sopenharmony_ci/* The process is similar if a callback is used, except the following: */
1380e41f4b71Sopenharmony_ci/* The key data imported may be different from the sample code given below. The data structure is described in the preceding comments. */
1381e41f4b71Sopenharmony_ciasync function TestImportWrappedFunc(alias: string, wrappingAlias: string, options: huks.HuksOptions) {
1382e41f4b71Sopenharmony_ci    try {
1383e41f4b71Sopenharmony_ci        await huks.importWrappedKeyItem(alias, wrappingAlias, options)
1384e41f4b71Sopenharmony_ci            .then ((data) => {
1385e41f4b71Sopenharmony_ci                console.info(`promise: importWrappedKeyItem success`);
1386e41f4b71Sopenharmony_ci            })
1387e41f4b71Sopenharmony_ci            .catch((error: Error) => {
1388e41f4b71Sopenharmony_ci                console.error(`promise: importWrappedKeyItem failed`);
1389e41f4b71Sopenharmony_ci            });
1390e41f4b71Sopenharmony_ci    } catch (error) {
1391e41f4b71Sopenharmony_ci        console.error(`promise: importWrappedKeyItem input arg invalid`);
1392e41f4b71Sopenharmony_ci    }
1393e41f4b71Sopenharmony_ci}
1394e41f4b71Sopenharmony_ci```
1395e41f4b71Sopenharmony_ci
1396e41f4b71Sopenharmony_ci## huks.exportKeyItem<sup>9+</sup>
1397e41f4b71Sopenharmony_ci
1398e41f4b71Sopenharmony_ciexportKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksReturnResult>) : void
1399e41f4b71Sopenharmony_ci
1400e41f4b71Sopenharmony_ciExports a key. This API uses an asynchronous callback to return the result.
1401e41f4b71Sopenharmony_ci
1402e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1403e41f4b71Sopenharmony_ci
1404e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
1405e41f4b71Sopenharmony_ci
1406e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 9 to 11, and **SystemCapability.Security.Huks.Core** since API version 12.
1407e41f4b71Sopenharmony_ci
1408e41f4b71Sopenharmony_ci**Parameters**
1409e41f4b71Sopenharmony_ci
1410e41f4b71Sopenharmony_ci| Name  | Type                                                | Mandatory| Description                                                        |
1411e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
1412e41f4b71Sopenharmony_ci| keyAlias | string                                               | Yes  | Key alias, which must be the same as the alias used when the key was generated.                |
1413e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                          | Yes  | Empty object (leave this parameter empty).                                    |
1414e41f4b71Sopenharmony_ci| callback | AsyncCallback<[HuksReturnResult](#huksreturnresult9)> | Yes  | Callback used to return the result. If the operation is successful, no **err** value is returned and **outData** contains the public key exported. Otherwise, an error code is returned.|
1415e41f4b71Sopenharmony_ci
1416e41f4b71Sopenharmony_ci**Error codes**
1417e41f4b71Sopenharmony_ci
1418e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1419e41f4b71Sopenharmony_ci
1420e41f4b71Sopenharmony_ci| ID| Error Message     |
1421e41f4b71Sopenharmony_ci| -------- | ------------- |
1422e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1423e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1424e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
1425e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1426e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1427e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1428e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1429e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1430e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1431e41f4b71Sopenharmony_ci| 12000012 | external error. |
1432e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1433e41f4b71Sopenharmony_ci
1434e41f4b71Sopenharmony_ci**Example**
1435e41f4b71Sopenharmony_ci
1436e41f4b71Sopenharmony_ci```ts
1437e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1438e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
1439e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
1440e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
1441e41f4b71Sopenharmony_ci    properties: []
1442e41f4b71Sopenharmony_ci};
1443e41f4b71Sopenharmony_citry {
1444e41f4b71Sopenharmony_ci    huks.exportKeyItem(keyAlias, emptyOptions, (error, data) => {
1445e41f4b71Sopenharmony_ci        if (error) {
1446e41f4b71Sopenharmony_ci            console.error(`callback: exportKeyItem failed`);
1447e41f4b71Sopenharmony_ci        } else {
1448e41f4b71Sopenharmony_ci            console.info(`callback: exportKeyItem success, data = ${JSON.stringify(data)}`);
1449e41f4b71Sopenharmony_ci        }
1450e41f4b71Sopenharmony_ci    });
1451e41f4b71Sopenharmony_ci} catch (error) {
1452e41f4b71Sopenharmony_ci    console.error(`callback: exportKeyItem input arg invalid`);
1453e41f4b71Sopenharmony_ci}
1454e41f4b71Sopenharmony_ci```
1455e41f4b71Sopenharmony_ci
1456e41f4b71Sopenharmony_ci## huks.exportKeyItem<sup>9+</sup>
1457e41f4b71Sopenharmony_ci
1458e41f4b71Sopenharmony_ciexportKeyItem(keyAlias: string, options: HuksOptions) : Promise\<HuksReturnResult>
1459e41f4b71Sopenharmony_ci
1460e41f4b71Sopenharmony_ciExports a key. This API uses a promise to return the result.
1461e41f4b71Sopenharmony_ci
1462e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1463e41f4b71Sopenharmony_ci
1464e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
1465e41f4b71Sopenharmony_ci
1466e41f4b71Sopenharmony_ci**Parameters**
1467e41f4b71Sopenharmony_ci
1468e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                        |
1469e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | -------------------------------------------- |
1470e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Key alias, which must be the same as the alias used when the key was generated.|
1471e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Empty object (leave this parameter empty).                    |
1472e41f4b71Sopenharmony_ci
1473e41f4b71Sopenharmony_ci**Return value**
1474e41f4b71Sopenharmony_ci
1475e41f4b71Sopenharmony_ci| Type                                          | Description                                                        |
1476e41f4b71Sopenharmony_ci| ---------------------------------------------- | ------------------------------------------------------------ |
1477e41f4b71Sopenharmony_ci| Promise<[HuksReturnResult](#huksreturnresult9)> | Promise used to return the result. If the operation is successful, **outData** in **HuksReturnResult** is the public key exported.|
1478e41f4b71Sopenharmony_ci
1479e41f4b71Sopenharmony_ci**Error codes**
1480e41f4b71Sopenharmony_ci
1481e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1482e41f4b71Sopenharmony_ci
1483e41f4b71Sopenharmony_ci| ID| Error Message     |
1484e41f4b71Sopenharmony_ci| -------- | ------------- |
1485e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1486e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1487e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
1488e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1489e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1490e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1491e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1492e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1493e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1494e41f4b71Sopenharmony_ci| 12000012 | external error. |
1495e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1496e41f4b71Sopenharmony_ci
1497e41f4b71Sopenharmony_ci**Example**
1498e41f4b71Sopenharmony_ci
1499e41f4b71Sopenharmony_ci```ts
1500e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1501e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
1502e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
1503e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
1504e41f4b71Sopenharmony_ci    properties: []
1505e41f4b71Sopenharmony_ci};
1506e41f4b71Sopenharmony_citry {
1507e41f4b71Sopenharmony_ci    huks.exportKeyItem(keyAlias, emptyOptions)
1508e41f4b71Sopenharmony_ci        .then ((data) => {
1509e41f4b71Sopenharmony_ci            console.info(`promise: exportKeyItem success, data = ${JSON.stringify(data)}`);
1510e41f4b71Sopenharmony_ci        })
1511e41f4b71Sopenharmony_ci        .catch((error: Error) => {
1512e41f4b71Sopenharmony_ci            console.error(`promise: exportKeyItem failed`);
1513e41f4b71Sopenharmony_ci        });
1514e41f4b71Sopenharmony_ci} catch (error) {
1515e41f4b71Sopenharmony_ci    console.error(`promise: exportKeyItem input arg invalid`);
1516e41f4b71Sopenharmony_ci}
1517e41f4b71Sopenharmony_ci```
1518e41f4b71Sopenharmony_ci
1519e41f4b71Sopenharmony_ci## huks.getKeyItemProperties<sup>9+</sup>
1520e41f4b71Sopenharmony_ci
1521e41f4b71Sopenharmony_cigetKeyItemProperties(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksReturnResult>) : void
1522e41f4b71Sopenharmony_ci
1523e41f4b71Sopenharmony_ciObtains key properties. This API uses an asynchronous callback to return the result.
1524e41f4b71Sopenharmony_ci
1525e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1526e41f4b71Sopenharmony_ci
1527e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
1528e41f4b71Sopenharmony_ci
1529e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 9 to 11, and **SystemCapability.Security.Huks.Core** since API version 12.
1530e41f4b71Sopenharmony_ci
1531e41f4b71Sopenharmony_ci**Parameters**
1532e41f4b71Sopenharmony_ci
1533e41f4b71Sopenharmony_ci| Name  | Type                                                | Mandatory| Description                                                        |
1534e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
1535e41f4b71Sopenharmony_ci| keyAlias | string                                               | Yes  | Key alias, which must be the same as the alias used when the key was generated.                |
1536e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                          | Yes  | Empty object (leave this parameter empty).                                    |
1537e41f4b71Sopenharmony_ci| callback | AsyncCallback<[HuksReturnResult](#huksreturnresult9)> | Yes  | Callback used to return the result. If the operation is successful, no **err** value is returned and **properties** contains the parameters required for generating the key. If the operation fails, an error code is returned.|
1538e41f4b71Sopenharmony_ci
1539e41f4b71Sopenharmony_ci**Error codes**
1540e41f4b71Sopenharmony_ci
1541e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1542e41f4b71Sopenharmony_ci
1543e41f4b71Sopenharmony_ci| ID| Error Message     |
1544e41f4b71Sopenharmony_ci| -------- | ------------- |
1545e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1546e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1547e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
1548e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1549e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1550e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1551e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1552e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1553e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1554e41f4b71Sopenharmony_ci| 12000012 | external error. |
1555e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1556e41f4b71Sopenharmony_ci
1557e41f4b71Sopenharmony_ci**Example**
1558e41f4b71Sopenharmony_ci
1559e41f4b71Sopenharmony_ci```ts
1560e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1561e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
1562e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
1563e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
1564e41f4b71Sopenharmony_ci    properties: []
1565e41f4b71Sopenharmony_ci};
1566e41f4b71Sopenharmony_citry {
1567e41f4b71Sopenharmony_ci    huks.getKeyItemProperties(keyAlias, emptyOptions, (error, data) => {
1568e41f4b71Sopenharmony_ci        if (error) {
1569e41f4b71Sopenharmony_ci            console.error(`callback: getKeyItemProperties failed`);
1570e41f4b71Sopenharmony_ci        } else {
1571e41f4b71Sopenharmony_ci            console.info(`callback: getKeyItemProperties success, data = ${JSON.stringify(data)}`);
1572e41f4b71Sopenharmony_ci        }
1573e41f4b71Sopenharmony_ci    });
1574e41f4b71Sopenharmony_ci} catch (error) {
1575e41f4b71Sopenharmony_ci    console.error(`callback: getKeyItemProperties input arg invalid`);
1576e41f4b71Sopenharmony_ci}
1577e41f4b71Sopenharmony_ci```
1578e41f4b71Sopenharmony_ci
1579e41f4b71Sopenharmony_ci## huks.getKeyItemProperties<sup>9+</sup>
1580e41f4b71Sopenharmony_ci
1581e41f4b71Sopenharmony_cigetKeyItemProperties(keyAlias: string, options: HuksOptions) : Promise\<HuksReturnResult>
1582e41f4b71Sopenharmony_ci
1583e41f4b71Sopenharmony_ciObtains key properties. This API uses a promise to return the result.
1584e41f4b71Sopenharmony_ci
1585e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1586e41f4b71Sopenharmony_ci
1587e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
1588e41f4b71Sopenharmony_ci
1589e41f4b71Sopenharmony_ci**Parameters**
1590e41f4b71Sopenharmony_ci
1591e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                        |
1592e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | -------------------------------------------- |
1593e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Key alias, which must be the same as the alias used when the key was generated.|
1594e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Empty object (leave this parameter empty).                    |
1595e41f4b71Sopenharmony_ci
1596e41f4b71Sopenharmony_ci**Return value**
1597e41f4b71Sopenharmony_ci
1598e41f4b71Sopenharmony_ci| Type                                           | Description                                                        |
1599e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------------------ |
1600e41f4b71Sopenharmony_ci| Promise\<[HuksReturnResult](#huksreturnresult9)> | Promise used to return the result. If the operation is successful, **properties** in **HuksReturnResult** holds the parameters required for generating the key.|
1601e41f4b71Sopenharmony_ci
1602e41f4b71Sopenharmony_ci**Error codes**
1603e41f4b71Sopenharmony_ci
1604e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1605e41f4b71Sopenharmony_ci
1606e41f4b71Sopenharmony_ci| ID| Error Message     |
1607e41f4b71Sopenharmony_ci| -------- | ------------- |
1608e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1609e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1610e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
1611e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1612e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1613e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1614e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1615e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1616e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1617e41f4b71Sopenharmony_ci| 12000012 | external error. |
1618e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1619e41f4b71Sopenharmony_ci
1620e41f4b71Sopenharmony_ci**Example**
1621e41f4b71Sopenharmony_ci
1622e41f4b71Sopenharmony_ci```ts
1623e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1624e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
1625e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
1626e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
1627e41f4b71Sopenharmony_ci    properties: []
1628e41f4b71Sopenharmony_ci};
1629e41f4b71Sopenharmony_citry {
1630e41f4b71Sopenharmony_ci    huks.getKeyItemProperties(keyAlias, emptyOptions)
1631e41f4b71Sopenharmony_ci        .then ((data) => {
1632e41f4b71Sopenharmony_ci            console.info(`promise: getKeyItemProperties success, data = ${JSON.stringify(data)}`);
1633e41f4b71Sopenharmony_ci        })
1634e41f4b71Sopenharmony_ci        .catch((error: Error) => {
1635e41f4b71Sopenharmony_ci            console.error(`promise: getKeyItemProperties failed`);
1636e41f4b71Sopenharmony_ci        });
1637e41f4b71Sopenharmony_ci} catch (error) {
1638e41f4b71Sopenharmony_ci    console.error(`promise: getKeyItemProperties input arg invalid`);
1639e41f4b71Sopenharmony_ci}
1640e41f4b71Sopenharmony_ci```
1641e41f4b71Sopenharmony_ci
1642e41f4b71Sopenharmony_ci## huks.isKeyItemExist<sup>9+</sup>
1643e41f4b71Sopenharmony_ci
1644e41f4b71Sopenharmony_ciisKeyItemExist(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<boolean>) : void
1645e41f4b71Sopenharmony_ci
1646e41f4b71Sopenharmony_ciChecks whether a key exists. This API uses an asynchronous callback to return the result.
1647e41f4b71Sopenharmony_ci
1648e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
1649e41f4b71Sopenharmony_ci
1650e41f4b71Sopenharmony_ci**Parameters**
1651e41f4b71Sopenharmony_ci
1652e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                                    |
1653e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- |--------------------------------------------------------|
1654e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key to check.                                           |
1655e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Options for checking the key. For example, you can pass in [HuksAuthStorageLevel](#huksauthstoragelevel11) to specify the security level of the key to check. **HuksAuthStorageLevel** can be left empty, which means the default value **HUKS_AUTH_STORAGE_LEVEL_DE** is used.    |
1656e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean>     | Yes  | Callback used to return the result. If the key exists, **data** is **true**. If the key does not exist, **error** is the error code.|
1657e41f4b71Sopenharmony_ci
1658e41f4b71Sopenharmony_ci**Error codes**
1659e41f4b71Sopenharmony_ci
1660e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1661e41f4b71Sopenharmony_ci
1662e41f4b71Sopenharmony_ci| ID| Error Message     |
1663e41f4b71Sopenharmony_ci| -------- | ------------- |
1664e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1665e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1666e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1667e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1668e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1669e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1670e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1671e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1672e41f4b71Sopenharmony_ci| 12000012 | external error. |
1673e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1674e41f4b71Sopenharmony_ci
1675e41f4b71Sopenharmony_ci**Example**
1676e41f4b71Sopenharmony_ci
1677e41f4b71Sopenharmony_ci```ts
1678e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1679e41f4b71Sopenharmony_ciimport { promptAction } from '@kit.ArkUI';
1680e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
1681e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
1682e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
1683e41f4b71Sopenharmony_ci    properties: []
1684e41f4b71Sopenharmony_ci};
1685e41f4b71Sopenharmony_cihuks.isKeyItemExist(keyAlias, emptyOptions, (error, data) => {
1686e41f4b71Sopenharmony_ci    if (data) {
1687e41f4b71Sopenharmony_ci        promptAction.showToast({
1688e41f4b71Sopenharmony_ci            message: "keyAlias: " + keyAlias +"is existed! ",
1689e41f4b71Sopenharmony_ci            duration: 2500,
1690e41f4b71Sopenharmony_ci        })
1691e41f4b71Sopenharmony_ci    } else {
1692e41f4b71Sopenharmony_ci        promptAction.showToast({
1693e41f4b71Sopenharmony_ci            message: "find key failed",
1694e41f4b71Sopenharmony_ci            duration: 2500,
1695e41f4b71Sopenharmony_ci        })
1696e41f4b71Sopenharmony_ci    }
1697e41f4b71Sopenharmony_ci});
1698e41f4b71Sopenharmony_ci```
1699e41f4b71Sopenharmony_ci
1700e41f4b71Sopenharmony_ci## huks.isKeyItemExist<sup>9+</sup>
1701e41f4b71Sopenharmony_ci
1702e41f4b71Sopenharmony_ciisKeyItemExist(keyAlias: string, options: HuksOptions) : Promise\<boolean>
1703e41f4b71Sopenharmony_ci
1704e41f4b71Sopenharmony_ciChecks whether a key exists. This API uses a promise to return the result.
1705e41f4b71Sopenharmony_ci
1706e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
1707e41f4b71Sopenharmony_ci
1708e41f4b71Sopenharmony_ci**Parameters**
1709e41f4b71Sopenharmony_ci
1710e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                    |
1711e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------ |
1712e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key to check.  |
1713e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Options for checking the key. For example, you can pass in [HuksAuthStorageLevel](#huksauthstoragelevel11) to specify the security level of the key to check. **HuksAuthStorageLevel** can be left empty, which means the default value **HUKS_AUTH_STORAGE_LEVEL_DE** is used.|
1714e41f4b71Sopenharmony_ci
1715e41f4b71Sopenharmony_ci**Return value**
1716e41f4b71Sopenharmony_ci
1717e41f4b71Sopenharmony_ci| Type             | Description                                   |
1718e41f4b71Sopenharmony_ci| ----------------- | --------------------------------------- |
1719e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. If the key exists, then() performs subsequent operations. If the key does not exist, error() performs the related service operations.|
1720e41f4b71Sopenharmony_ci
1721e41f4b71Sopenharmony_ci**Error codes**
1722e41f4b71Sopenharmony_ci
1723e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1724e41f4b71Sopenharmony_ci
1725e41f4b71Sopenharmony_ci| ID| Error Message     |
1726e41f4b71Sopenharmony_ci| -------- | ------------- |
1727e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1728e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1729e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1730e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1731e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1732e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1733e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1734e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1735e41f4b71Sopenharmony_ci| 12000012 | external error. |
1736e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1737e41f4b71Sopenharmony_ci
1738e41f4b71Sopenharmony_ci**Example**
1739e41f4b71Sopenharmony_ci
1740e41f4b71Sopenharmony_ci```ts
1741e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1742e41f4b71Sopenharmony_ciimport { promptAction } from '@kit.ArkUI';
1743e41f4b71Sopenharmony_ci
1744e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
1745e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
1746e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
1747e41f4b71Sopenharmony_ci    properties: []
1748e41f4b71Sopenharmony_ci};
1749e41f4b71Sopenharmony_cihuks.isKeyItemExist(keyAlias, emptyOptions).then((data) => {
1750e41f4b71Sopenharmony_ci    promptAction.showToast({
1751e41f4b71Sopenharmony_ci        message: "keyAlias: " + keyAlias +"is existed! ",
1752e41f4b71Sopenharmony_ci        duration: 500,
1753e41f4b71Sopenharmony_ci    })
1754e41f4b71Sopenharmony_ci}).catch((error: Error)=>{
1755e41f4b71Sopenharmony_ci    promptAction.showToast({
1756e41f4b71Sopenharmony_ci        message: "find key failed",
1757e41f4b71Sopenharmony_ci        duration: 6500,
1758e41f4b71Sopenharmony_ci    })
1759e41f4b71Sopenharmony_ci})
1760e41f4b71Sopenharmony_ci```
1761e41f4b71Sopenharmony_ci
1762e41f4b71Sopenharmony_ci## huks.hasKeyItem<sup>11+</sup>
1763e41f4b71Sopenharmony_ci
1764e41f4b71Sopenharmony_cihasKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<boolean>) : void
1765e41f4b71Sopenharmony_ci
1766e41f4b71Sopenharmony_ciChecks whether a key exists. This API uses an asynchronous callback to return the result.
1767e41f4b71Sopenharmony_ci
1768e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1769e41f4b71Sopenharmony_ci
1770e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
1771e41f4b71Sopenharmony_ci
1772e41f4b71Sopenharmony_ci**Parameters**
1773e41f4b71Sopenharmony_ci
1774e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                                    |
1775e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- |--------------------------------------------------------|
1776e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key to check.                                           |
1777e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Options for checking the key. For example, you can pass in [HuksAuthStorageLevel](#huksauthstoragelevel11) to specify the security level of the key to check. **HuksAuthStorageLevel** can be left empty, which means the default value **HUKS_AUTH_STORAGE_LEVEL_DE** is used.    |
1778e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean>     | Yes  | Callback used to return the result. If the key exists, **data** is **true**. Otherwise, **data** is **false**.|
1779e41f4b71Sopenharmony_ci
1780e41f4b71Sopenharmony_ci**Error codes**
1781e41f4b71Sopenharmony_ci
1782e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1783e41f4b71Sopenharmony_ci
1784e41f4b71Sopenharmony_ci| ID| Error Message     |
1785e41f4b71Sopenharmony_ci| -------- | ------------- |
1786e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1787e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1788e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1789e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1790e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1791e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1792e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1793e41f4b71Sopenharmony_ci| 12000012 | external error. |
1794e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1795e41f4b71Sopenharmony_ci
1796e41f4b71Sopenharmony_ci**Example**
1797e41f4b71Sopenharmony_ci
1798e41f4b71Sopenharmony_ci```ts
1799e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1800e41f4b71Sopenharmony_ciimport { promptAction } from '@kit.ArkUI';
1801e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
1802e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
1803e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
1804e41f4b71Sopenharmony_ci    properties: []
1805e41f4b71Sopenharmony_ci};
1806e41f4b71Sopenharmony_ci
1807e41f4b71Sopenharmony_citry {
1808e41f4b71Sopenharmony_ci    huks.hasKeyItem(keyAlias, emptyOptions, (error, data) => {
1809e41f4b71Sopenharmony_ci        if (data) {
1810e41f4b71Sopenharmony_ci            promptAction.showToast({
1811e41f4b71Sopenharmony_ci                message: "keyAlias: " + keyAlias +" is existed!",
1812e41f4b71Sopenharmony_ci                duration: 2500,
1813e41f4b71Sopenharmony_ci            })
1814e41f4b71Sopenharmony_ci        } else {
1815e41f4b71Sopenharmony_ci            promptAction.showToast({
1816e41f4b71Sopenharmony_ci                message: "find key failed",
1817e41f4b71Sopenharmony_ci                duration: 2500,
1818e41f4b71Sopenharmony_ci            })
1819e41f4b71Sopenharmony_ci        }
1820e41f4b71Sopenharmony_ci    });
1821e41f4b71Sopenharmony_ci} catch (error) {
1822e41f4b71Sopenharmony_ci    console.error(`callback: hasKeyItem input args may be invalid`);
1823e41f4b71Sopenharmony_ci}
1824e41f4b71Sopenharmony_ci```
1825e41f4b71Sopenharmony_ci
1826e41f4b71Sopenharmony_ci## huks.hasKeyItem<sup>11+</sup>
1827e41f4b71Sopenharmony_ci
1828e41f4b71Sopenharmony_cihasKeyItem(keyAlias: string, options: HuksOptions) : Promise\<boolean>
1829e41f4b71Sopenharmony_ci
1830e41f4b71Sopenharmony_ciChecks whether a key exists. This API uses a promise to return the result.
1831e41f4b71Sopenharmony_ci
1832e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1833e41f4b71Sopenharmony_ci
1834e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
1835e41f4b71Sopenharmony_ci
1836e41f4b71Sopenharmony_ci**Parameters**
1837e41f4b71Sopenharmony_ci
1838e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                    |
1839e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------ |
1840e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key to check.  |
1841e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Options for checking the key. For example, you can pass in [HuksAuthStorageLevel](#huksauthstoragelevel11) to specify the security level of the key to check. **HuksAuthStorageLevel** can be left empty, which means the default value **HUKS_AUTH_STORAGE_LEVEL_DE** is used.    |
1842e41f4b71Sopenharmony_ci
1843e41f4b71Sopenharmony_ci**Return value**
1844e41f4b71Sopenharmony_ci
1845e41f4b71Sopenharmony_ci| Type             | Description                                   |
1846e41f4b71Sopenharmony_ci| ----------------- | --------------------------------------- |
1847e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. If the key exists, **true** is returned. If the key does not exist, **false** is returned.|
1848e41f4b71Sopenharmony_ci
1849e41f4b71Sopenharmony_ci**Error codes**
1850e41f4b71Sopenharmony_ci
1851e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1852e41f4b71Sopenharmony_ci
1853e41f4b71Sopenharmony_ci| ID| Error Message     |
1854e41f4b71Sopenharmony_ci| -------- | ------------- |
1855e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1856e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1857e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1858e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1859e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1860e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1861e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1862e41f4b71Sopenharmony_ci| 12000012 | external error. |
1863e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1864e41f4b71Sopenharmony_ci
1865e41f4b71Sopenharmony_ci**Example**
1866e41f4b71Sopenharmony_ci
1867e41f4b71Sopenharmony_ci```ts
1868e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
1869e41f4b71Sopenharmony_ciimport { promptAction } from '@kit.ArkUI';
1870e41f4b71Sopenharmony_ci
1871e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
1872e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
1873e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
1874e41f4b71Sopenharmony_ci    properties: []
1875e41f4b71Sopenharmony_ci};
1876e41f4b71Sopenharmony_cihuks.hasKeyItem(keyAlias, emptyOptions).then((data) => {
1877e41f4b71Sopenharmony_ci    if (data) {
1878e41f4b71Sopenharmony_ci        promptAction.showToast({
1879e41f4b71Sopenharmony_ci            message: "keyAlias: " + keyAlias +" is existed!",
1880e41f4b71Sopenharmony_ci            duration: 2500,
1881e41f4b71Sopenharmony_ci        })
1882e41f4b71Sopenharmony_ci    } else {
1883e41f4b71Sopenharmony_ci        promptAction.showToast({
1884e41f4b71Sopenharmony_ci            message: "find key failed",
1885e41f4b71Sopenharmony_ci            duration: 2500,
1886e41f4b71Sopenharmony_ci        })
1887e41f4b71Sopenharmony_ci    }
1888e41f4b71Sopenharmony_ci}).catch((error: Error)=>{
1889e41f4b71Sopenharmony_ci    promptAction.showToast({
1890e41f4b71Sopenharmony_ci        message: "find key failed",
1891e41f4b71Sopenharmony_ci        duration: 6500,
1892e41f4b71Sopenharmony_ci    })
1893e41f4b71Sopenharmony_ci})
1894e41f4b71Sopenharmony_ci```
1895e41f4b71Sopenharmony_ci
1896e41f4b71Sopenharmony_ci## huks.initSession<sup>9+</sup>
1897e41f4b71Sopenharmony_ci
1898e41f4b71Sopenharmony_ciinitSession(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksSessionHandle>) : void
1899e41f4b71Sopenharmony_ci
1900e41f4b71Sopenharmony_ciInitializes a session for a key operation. This API uses an asynchronous callback to return the result. **huks.initSession**, **huks.updateSession**, and **huks.finishSession** must be used together.
1901e41f4b71Sopenharmony_ci
1902e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1903e41f4b71Sopenharmony_ci
1904e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
1905e41f4b71Sopenharmony_ci
1906e41f4b71Sopenharmony_ci**Parameters**
1907e41f4b71Sopenharmony_ci
1908e41f4b71Sopenharmony_ci| Name  | Type                                                   | Mandatory| Description                                                |
1909e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------- | ---- | ---------------------------------------------------- |
1910e41f4b71Sopenharmony_ci| keyAlias | string                                                  | Yes  | Alias of the key involved in the **initSession** operation.                                |
1911e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                             | Yes  | Parameter set used for the **initSession** operation.                                |
1912e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksSessionHandle](#hukssessionhandle9)> | Yes  | Callback used to return a session handle for subsequent operations.|
1913e41f4b71Sopenharmony_ci
1914e41f4b71Sopenharmony_ci**Error codes**
1915e41f4b71Sopenharmony_ci
1916e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1917e41f4b71Sopenharmony_ci
1918e41f4b71Sopenharmony_ci| ID| Error Message     |
1919e41f4b71Sopenharmony_ci| -------- | ------------- |
1920e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1921e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1922e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
1923e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1924e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1925e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1926e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1927e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1928e41f4b71Sopenharmony_ci| 12000010 | the number of sessions has reached limit. |
1929e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1930e41f4b71Sopenharmony_ci| 12000012 | external error. |
1931e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1932e41f4b71Sopenharmony_ci
1933e41f4b71Sopenharmony_ci## huks.initSession<sup>9+</sup>
1934e41f4b71Sopenharmony_ci
1935e41f4b71Sopenharmony_ciinitSession(keyAlias: string, options: HuksOptions) : Promise\<HuksSessionHandle>
1936e41f4b71Sopenharmony_ci
1937e41f4b71Sopenharmony_ciInitializes a session for a key operation. This API uses a promise to return the result. **huks.initSession**, **huks.updateSession**, and **huks.finishSession** must be used together.
1938e41f4b71Sopenharmony_ci
1939e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1940e41f4b71Sopenharmony_ci
1941e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
1942e41f4b71Sopenharmony_ci
1943e41f4b71Sopenharmony_ci**Parameters**
1944e41f4b71Sopenharmony_ci
1945e41f4b71Sopenharmony_ci| Name  | Type                                             | Mandatory| Description                                            |
1946e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | ---- | ------------------------------------------------ |
1947e41f4b71Sopenharmony_ci| keyAlias | string                                            | Yes  | Alias of the key involved in the **initSession** operation.                            |
1948e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                       | Yes  | Parameter set used for the **initSession** operation.                                  |
1949e41f4b71Sopenharmony_ci
1950e41f4b71Sopenharmony_ci**Return value**
1951e41f4b71Sopenharmony_ci
1952e41f4b71Sopenharmony_ci| Type                               | Description                                              |
1953e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
1954e41f4b71Sopenharmony_ci| Promise\<[HuksSessionHandle](#hukssessionhandle9)> | Promise used to return a session handle for subsequent operations.|
1955e41f4b71Sopenharmony_ci
1956e41f4b71Sopenharmony_ci**Error codes**
1957e41f4b71Sopenharmony_ci
1958e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1959e41f4b71Sopenharmony_ci
1960e41f4b71Sopenharmony_ci| ID| Error Message     |
1961e41f4b71Sopenharmony_ci| -------- | ------------- |
1962e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
1963e41f4b71Sopenharmony_ci| 801 | api is not supported. |
1964e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
1965e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
1966e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
1967e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
1968e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
1969e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
1970e41f4b71Sopenharmony_ci| 12000010 | the number of sessions has reached limit. |
1971e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
1972e41f4b71Sopenharmony_ci| 12000012 | external error. |
1973e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
1974e41f4b71Sopenharmony_ci
1975e41f4b71Sopenharmony_ci## huks.updateSession<sup>9+</sup>
1976e41f4b71Sopenharmony_ci
1977e41f4b71Sopenharmony_ciupdateSession(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksReturnResult>) : void
1978e41f4b71Sopenharmony_ci
1979e41f4b71Sopenharmony_ciUpdates the key operation by segment. This API uses an asynchronous callback to return the result. **huks.initSession**, **huks.updateSession**, and **huks.finishSession** must be used together.
1980e41f4b71Sopenharmony_ci
1981e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1982e41f4b71Sopenharmony_ci
1983e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
1984e41f4b71Sopenharmony_ci
1985e41f4b71Sopenharmony_ci**Parameters**
1986e41f4b71Sopenharmony_ci
1987e41f4b71Sopenharmony_ci| Name  | Type                                                | Mandatory| Description                                        |
1988e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | -------------------------------------------- |
1989e41f4b71Sopenharmony_ci| handle   | number                                               | Yes  | Handle for the **updateSession** operation.                        |
1990e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                          | Yes  | Parameter set used for the **updateSession** operation.                          |
1991e41f4b71Sopenharmony_ci| callback | AsyncCallback<[HuksReturnResult](#huksreturnresult9)> | Yes  | Callback used to return the **updateSession** operation result.|
1992e41f4b71Sopenharmony_ci
1993e41f4b71Sopenharmony_ci**Error codes**
1994e41f4b71Sopenharmony_ci
1995e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
1996e41f4b71Sopenharmony_ci
1997e41f4b71Sopenharmony_ci| ID| Error Message     |
1998e41f4b71Sopenharmony_ci| -------- | ------------- |
1999e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
2000e41f4b71Sopenharmony_ci| 801 | api is not supported. |
2001e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
2002e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
2003e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
2004e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
2005e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
2006e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
2007e41f4b71Sopenharmony_ci| 12000007 | this credential is already invalidated permanently. |
2008e41f4b71Sopenharmony_ci| 12000008 | verify auth token failed. |
2009e41f4b71Sopenharmony_ci| 12000009 | auth token is already timeout. |
2010e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
2011e41f4b71Sopenharmony_ci| 12000012 | external error. |
2012e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
2013e41f4b71Sopenharmony_ci
2014e41f4b71Sopenharmony_ci## huks.updateSession<sup>9+</sup>
2015e41f4b71Sopenharmony_ci
2016e41f4b71Sopenharmony_ciupdateSession(handle: number, options: HuksOptions, token: Uint8Array, callback: AsyncCallback\<HuksReturnResult>) : void
2017e41f4b71Sopenharmony_ci
2018e41f4b71Sopenharmony_ciUpdates the key operation by segment. This API uses an asynchronous callback to return the result. **huks.initSession**, **huks.updateSession**, and **huks.finishSession** must be used together.
2019e41f4b71Sopenharmony_ci
2020e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2021e41f4b71Sopenharmony_ci
2022e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2023e41f4b71Sopenharmony_ci
2024e41f4b71Sopenharmony_ci**Parameters**
2025e41f4b71Sopenharmony_ci
2026e41f4b71Sopenharmony_ci| Name  | Type                                                | Mandatory| Description                                        |
2027e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | -------------------------------------------- |
2028e41f4b71Sopenharmony_ci| handle   | number                                               | Yes  | Handle for the **updateSession** operation.                        |
2029e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                          | Yes  | Parameter set used for the **updateSession** operation.                      |
2030e41f4b71Sopenharmony_ci| token    | Uint8Array                                           | Yes  | Authentication token for [refined key access control](../../security/UniversalKeystoreKit/huks-identity-authentication-overview.md).                        |
2031e41f4b71Sopenharmony_ci| callback | AsyncCallback<[HuksReturnResult](#huksreturnresult9)> | Yes  | Callback used to return the **updateSession** operation result.|
2032e41f4b71Sopenharmony_ci
2033e41f4b71Sopenharmony_ci**Error codes**
2034e41f4b71Sopenharmony_ci
2035e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
2036e41f4b71Sopenharmony_ci
2037e41f4b71Sopenharmony_ci| ID| Error Message     |
2038e41f4b71Sopenharmony_ci| -------- | ------------- |
2039e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
2040e41f4b71Sopenharmony_ci| 801 | api is not supported. |
2041e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
2042e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
2043e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
2044e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
2045e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
2046e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
2047e41f4b71Sopenharmony_ci| 12000007 | this credential is already invalidated permanently. |
2048e41f4b71Sopenharmony_ci| 12000008 | verify auth token failed. |
2049e41f4b71Sopenharmony_ci| 12000009 | auth token is already timeout. |
2050e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
2051e41f4b71Sopenharmony_ci| 12000012 | external error. |
2052e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
2053e41f4b71Sopenharmony_ci
2054e41f4b71Sopenharmony_ci## huks.updateSession<sup>9+</sup>
2055e41f4b71Sopenharmony_ci
2056e41f4b71Sopenharmony_ciupdateSession(handle: number, options: HuksOptions, token?: Uint8Array) : Promise\<HuksReturnResult>
2057e41f4b71Sopenharmony_ci
2058e41f4b71Sopenharmony_ciUpdates the key operation by segment. This API uses a promise to return the result. **huks.initSession**, **huks.updateSession**, and **huks.finishSession** must be used together.
2059e41f4b71Sopenharmony_ci
2060e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2061e41f4b71Sopenharmony_ci
2062e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2063e41f4b71Sopenharmony_ci
2064e41f4b71Sopenharmony_ci**Parameters**
2065e41f4b71Sopenharmony_ci
2066e41f4b71Sopenharmony_ci| Name | Type                                          | Mandatory| Description                                        |
2067e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------- | ---- | -------------------------------------------- |
2068e41f4b71Sopenharmony_ci| handle  | number                                         | Yes  | Handle for the **updateSession** operation.                        |
2069e41f4b71Sopenharmony_ci| options | [HuksOptions](#huksoptions)                    | Yes  | Parameter set used for the **updateSession** operation.                      |
2070e41f4b71Sopenharmony_ci| token   | Uint8Array                                     | No  |Authentication token for [refined key access control](../../security/UniversalKeystoreKit/huks-identity-authentication-overview.md). If this parameter is left blank, refined key access control is not performed.                         |
2071e41f4b71Sopenharmony_ci
2072e41f4b71Sopenharmony_ci**Return value**
2073e41f4b71Sopenharmony_ci
2074e41f4b71Sopenharmony_ci| Type                               | Description                                              |
2075e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
2076e41f4b71Sopenharmony_ci| Promise<[HuksReturnResult](#huksreturnresult9)> | Promise used to return the **updateSession** operation result.|
2077e41f4b71Sopenharmony_ci
2078e41f4b71Sopenharmony_ci**Error codes**
2079e41f4b71Sopenharmony_ci
2080e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
2081e41f4b71Sopenharmony_ci
2082e41f4b71Sopenharmony_ci| ID| Error Message     |
2083e41f4b71Sopenharmony_ci| -------- | ------------- |
2084e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
2085e41f4b71Sopenharmony_ci| 801 | api is not supported. |
2086e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
2087e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
2088e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
2089e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
2090e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
2091e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
2092e41f4b71Sopenharmony_ci| 12000007 | this credential is already invalidated permanently. |
2093e41f4b71Sopenharmony_ci| 12000008 | verify auth token failed. |
2094e41f4b71Sopenharmony_ci| 12000009 | auth token is already timeout. |
2095e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
2096e41f4b71Sopenharmony_ci| 12000012 | external error. |
2097e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
2098e41f4b71Sopenharmony_ci
2099e41f4b71Sopenharmony_ci## huks.finishSession<sup>9+</sup>
2100e41f4b71Sopenharmony_ci
2101e41f4b71Sopenharmony_cifinishSession(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksReturnResult>) : void
2102e41f4b71Sopenharmony_ci
2103e41f4b71Sopenharmony_ciFinishes the key operation. This API uses an asynchronous callback to return the result. **huks.initSession**, **huks.updateSession**, and **huks.finishSession** must be used together.
2104e41f4b71Sopenharmony_ci
2105e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2106e41f4b71Sopenharmony_ci
2107e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2108e41f4b71Sopenharmony_ci
2109e41f4b71Sopenharmony_ci**Parameters**
2110e41f4b71Sopenharmony_ci
2111e41f4b71Sopenharmony_ci| Name  | Type                                                | Mandatory| Description                                        |
2112e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------- | ---- | -------------------------------------------- |
2113e41f4b71Sopenharmony_ci| handle   | number                                               | Yes  | Handle for the **finishSession** operation.                        |
2114e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                          | Yes  | Parameter set used for the **finishSession** operation.                          |
2115e41f4b71Sopenharmony_ci| callback | AsyncCallback<[HuksReturnResult](#huksreturnresult9)> | Yes  | Callback used to return the **finishSession** operation result.|
2116e41f4b71Sopenharmony_ci
2117e41f4b71Sopenharmony_ci**Error codes**
2118e41f4b71Sopenharmony_ci
2119e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
2120e41f4b71Sopenharmony_ci
2121e41f4b71Sopenharmony_ci| ID| Error Message     |
2122e41f4b71Sopenharmony_ci| -------- | ------------- |
2123e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
2124e41f4b71Sopenharmony_ci| 801 | api is not supported. |
2125e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
2126e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
2127e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
2128e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
2129e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
2130e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
2131e41f4b71Sopenharmony_ci| 12000007 | this credential is already invalidated permanently. |
2132e41f4b71Sopenharmony_ci| 12000008 | verify auth token failed. |
2133e41f4b71Sopenharmony_ci| 12000009 | auth token is already timeout. |
2134e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
2135e41f4b71Sopenharmony_ci| 12000012 | external error. |
2136e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
2137e41f4b71Sopenharmony_ci
2138e41f4b71Sopenharmony_ci## huks.finishSession<sup>9+</sup>
2139e41f4b71Sopenharmony_ci
2140e41f4b71Sopenharmony_cifinishSession(handle: number, options: HuksOptions, token: Uint8Array, callback: AsyncCallback\<HuksReturnResult>) : void
2141e41f4b71Sopenharmony_ci
2142e41f4b71Sopenharmony_ciFinishes the key operation. This API uses an asynchronous callback to return the result. **huks.initSession**, **huks.updateSession**, and **huks.finishSession** must be used together.
2143e41f4b71Sopenharmony_ci
2144e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2145e41f4b71Sopenharmony_ci
2146e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2147e41f4b71Sopenharmony_ci
2148e41f4b71Sopenharmony_ci**Parameters**
2149e41f4b71Sopenharmony_ci
2150e41f4b71Sopenharmony_ci| Name  | Type                                                 | Mandatory| Description                                        |
2151e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | ---- | -------------------------------------------- |
2152e41f4b71Sopenharmony_ci| handle   | number                                                | Yes  | Handle for the **finishSession** operation.                        |
2153e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                           | Yes  | Parameter set used for the **finishSession** operation.                          |
2154e41f4b71Sopenharmony_ci| token    | Uint8Array                                            | Yes  | Authentication token for [refined key access control](../../security/UniversalKeystoreKit/huks-identity-authentication-overview.md).                        |
2155e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksReturnResult](#huksreturnresult9)> | Yes  | Callback used to return the **finishSession** operation result.|
2156e41f4b71Sopenharmony_ci
2157e41f4b71Sopenharmony_ci**Error codes**
2158e41f4b71Sopenharmony_ci
2159e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
2160e41f4b71Sopenharmony_ci
2161e41f4b71Sopenharmony_ci| ID| Error Message     |
2162e41f4b71Sopenharmony_ci| -------- | ------------- |
2163e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
2164e41f4b71Sopenharmony_ci| 801 | api is not supported. |
2165e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
2166e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
2167e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
2168e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
2169e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
2170e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
2171e41f4b71Sopenharmony_ci| 12000007 | this credential is already invalidated permanently. |
2172e41f4b71Sopenharmony_ci| 12000008 | verify auth token failed. |
2173e41f4b71Sopenharmony_ci| 12000009 | auth token is already timeout. |
2174e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
2175e41f4b71Sopenharmony_ci| 12000012 | external error. |
2176e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
2177e41f4b71Sopenharmony_ci
2178e41f4b71Sopenharmony_ci## huks.finishSession<sup>9+</sup>
2179e41f4b71Sopenharmony_ci
2180e41f4b71Sopenharmony_cifinishSession(handle: number, options: HuksOptions, token?: Uint8Array) : Promise\<HuksReturnResult>
2181e41f4b71Sopenharmony_ci
2182e41f4b71Sopenharmony_ciFinishes the key operation. This API uses a promise to return the result. **huks.initSession**, **huks.updateSession**, and **huks.finishSession** must be used together.
2183e41f4b71Sopenharmony_ci
2184e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2185e41f4b71Sopenharmony_ci
2186e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2187e41f4b71Sopenharmony_ci
2188e41f4b71Sopenharmony_ci**Parameters**
2189e41f4b71Sopenharmony_ci
2190e41f4b71Sopenharmony_ci| Name | Type                                           | Mandatory| Description                               |
2191e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------- | ---- | ----------------------------------- |
2192e41f4b71Sopenharmony_ci| handle  | number                                          | Yes  | Handle for the **finishSession** operation.               |
2193e41f4b71Sopenharmony_ci| options | [HuksOptions](#huksoptions)                     | Yes  | Parameter set used for the **finishSession** operation.             |
2194e41f4b71Sopenharmony_ci| token   | Uint8Array                                      | No  | Authentication token for [refined key access control](../../security/UniversalKeystoreKit/huks-identity-authentication-overview.md). If this parameter is left blank, refined key access control is not performed.    |
2195e41f4b71Sopenharmony_ci
2196e41f4b71Sopenharmony_ci**Return value**
2197e41f4b71Sopenharmony_ci
2198e41f4b71Sopenharmony_ci| Type                               | Description                                              |
2199e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
2200e41f4b71Sopenharmony_ci| Promise\<[HuksReturnResult](#huksreturnresult9)> | Promise used to return the result.|
2201e41f4b71Sopenharmony_ci
2202e41f4b71Sopenharmony_ci**Error codes**
2203e41f4b71Sopenharmony_ci
2204e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
2205e41f4b71Sopenharmony_ci
2206e41f4b71Sopenharmony_ci| ID| Error Message     |
2207e41f4b71Sopenharmony_ci| -------- | ------------- |
2208e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
2209e41f4b71Sopenharmony_ci| 801 | api is not supported. |
2210e41f4b71Sopenharmony_ci| 12000001 | algorithm mode is not supported. |
2211e41f4b71Sopenharmony_ci| 12000002 | algorithm param is missing. |
2212e41f4b71Sopenharmony_ci| 12000003 | algorithm param is invalid. |
2213e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
2214e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
2215e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
2216e41f4b71Sopenharmony_ci| 12000007 | this credential is already invalidated permanently. |
2217e41f4b71Sopenharmony_ci| 12000008 | verify auth token failed. |
2218e41f4b71Sopenharmony_ci| 12000009 | auth token is already timeout. |
2219e41f4b71Sopenharmony_ci| 12000011 | queried entity does not exist. |
2220e41f4b71Sopenharmony_ci| 12000012 | external error. |
2221e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
2222e41f4b71Sopenharmony_ci
2223e41f4b71Sopenharmony_ci## huks.abortSession<sup>9+</sup>
2224e41f4b71Sopenharmony_ci
2225e41f4b71Sopenharmony_ciabortSession(handle: number, options: HuksOptions, callback: AsyncCallback\<void>) : void
2226e41f4b71Sopenharmony_ci
2227e41f4b71Sopenharmony_ciAborts a key operation. This API uses an asynchronous callback to return the result.
2228e41f4b71Sopenharmony_ci
2229e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2230e41f4b71Sopenharmony_ci
2231e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2232e41f4b71Sopenharmony_ci
2233e41f4b71Sopenharmony_ci**Parameters**
2234e41f4b71Sopenharmony_ci
2235e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                       |
2236e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------------------------- |
2237e41f4b71Sopenharmony_ci| handle   | number                      | Yes  | Handle for the **abortSession** operation.                        |
2238e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Parameter set used for the **abortSession** operation.                      |
2239e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>        | Yes  | Callback used to return the **abortSession** operation result.|
2240e41f4b71Sopenharmony_ci
2241e41f4b71Sopenharmony_ci**Error codes**
2242e41f4b71Sopenharmony_ci
2243e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
2244e41f4b71Sopenharmony_ci
2245e41f4b71Sopenharmony_ci| ID| Error Message     |
2246e41f4b71Sopenharmony_ci| -------- | ------------- |
2247e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
2248e41f4b71Sopenharmony_ci| 801 | api is not supported. |
2249e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
2250e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
2251e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
2252e41f4b71Sopenharmony_ci| 12000012 | external error. |
2253e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
2254e41f4b71Sopenharmony_ci
2255e41f4b71Sopenharmony_ci**Example**
2256e41f4b71Sopenharmony_ci
2257e41f4b71Sopenharmony_ci```ts
2258e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
2259e41f4b71Sopenharmony_ci/* huks.initSession, huks.updateSession, and huks.finishSession must be used together.
2260e41f4b71Sopenharmony_ci * If an error occurs in any of huks.initSession, huks.updateSession,
2261e41f4b71Sopenharmony_ci * and huks.finishSession operations,
2262e41f4b71Sopenharmony_ci * call huks.abortSession to terminate the use of the key.
2263e41f4b71Sopenharmony_ci *
2264e41f4b71Sopenharmony_ci * The following uses a 2048-bit RSA key as an example. The callback-based APIs are used.
2265e41f4b71Sopenharmony_ci */
2266e41f4b71Sopenharmony_ci
2267e41f4b71Sopenharmony_cilet keyAlias = "HuksDemoRSA";
2268e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = []
2269e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
2270e41f4b71Sopenharmony_ci    properties: properties,
2271e41f4b71Sopenharmony_ci    inData: new Uint8Array(0)
2272e41f4b71Sopenharmony_ci};
2273e41f4b71Sopenharmony_cilet handle: number = 0;
2274e41f4b71Sopenharmony_ciasync function huksAbort() {
2275e41f4b71Sopenharmony_ci    properties[0] = {
2276e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
2277e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_RSA
2278e41f4b71Sopenharmony_ci    };
2279e41f4b71Sopenharmony_ci    properties[1] = {
2280e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
2281e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048
2282e41f4b71Sopenharmony_ci    };
2283e41f4b71Sopenharmony_ci    properties[2] = {
2284e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
2285e41f4b71Sopenharmony_ci        value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT
2286e41f4b71Sopenharmony_ci    };
2287e41f4b71Sopenharmony_ci    properties[3] = {
2288e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PADDING,
2289e41f4b71Sopenharmony_ci        value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5
2290e41f4b71Sopenharmony_ci    };
2291e41f4b71Sopenharmony_ci    properties[4] = {
2292e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_DIGEST,
2293e41f4b71Sopenharmony_ci        value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
2294e41f4b71Sopenharmony_ci    };
2295e41f4b71Sopenharmony_ci    properties[5] = {
2296e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
2297e41f4b71Sopenharmony_ci        value: huks.HuksCipherMode.HUKS_MODE_ECB,
2298e41f4b71Sopenharmony_ci    }
2299e41f4b71Sopenharmony_ci    try {
2300e41f4b71Sopenharmony_ci        huks.generateKeyItem(keyAlias, options, (error, data) => {
2301e41f4b71Sopenharmony_ci            if (error) {
2302e41f4b71Sopenharmony_ci                console.error(`callback: generateKeyItem failed`);
2303e41f4b71Sopenharmony_ci            } else {
2304e41f4b71Sopenharmony_ci                console.info(`callback: generateKeyItem success`);
2305e41f4b71Sopenharmony_ci                huks.initSession(keyAlias, options, (error, data) => {// Use abortSession to abort initSession.
2306e41f4b71Sopenharmony_ci                    if (error) {
2307e41f4b71Sopenharmony_ci                        console.error(`callback: initSession failed`);
2308e41f4b71Sopenharmony_ci                    } else {
2309e41f4b71Sopenharmony_ci                        console.info(`callback: initSession success, data = ${JSON.stringify(data)}`);
2310e41f4b71Sopenharmony_ci                        handle = data.handle;
2311e41f4b71Sopenharmony_ci                        huks.abortSession(handle, options, (error, data) => {
2312e41f4b71Sopenharmony_ci                            if (error) {
2313e41f4b71Sopenharmony_ci                                console.error(`callback: abortSession failed`);
2314e41f4b71Sopenharmony_ci                            } else {
2315e41f4b71Sopenharmony_ci                                console.info(`callback: abortSession success`);
2316e41f4b71Sopenharmony_ci                            }
2317e41f4b71Sopenharmony_ci                        });
2318e41f4b71Sopenharmony_ci                    }
2319e41f4b71Sopenharmony_ci                });
2320e41f4b71Sopenharmony_ci            }
2321e41f4b71Sopenharmony_ci        });
2322e41f4b71Sopenharmony_ci    } catch (error) {
2323e41f4b71Sopenharmony_ci        console.error(`callback: huksAbort failed`);
2324e41f4b71Sopenharmony_ci    }
2325e41f4b71Sopenharmony_ci}
2326e41f4b71Sopenharmony_ci```
2327e41f4b71Sopenharmony_ci
2328e41f4b71Sopenharmony_ci## huks.abortSession<sup>9+</sup>
2329e41f4b71Sopenharmony_ci
2330e41f4b71Sopenharmony_ciabortSession(handle: number, options: HuksOptions) : Promise\<void>;
2331e41f4b71Sopenharmony_ci
2332e41f4b71Sopenharmony_ciAborts a key operation. This API uses a promise to return the result.
2333e41f4b71Sopenharmony_ci
2334e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2335e41f4b71Sopenharmony_ci
2336e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2337e41f4b71Sopenharmony_ci
2338e41f4b71Sopenharmony_ci**Parameters**
2339e41f4b71Sopenharmony_ci
2340e41f4b71Sopenharmony_ci| Name | Type                       | Mandatory| Description                                       |
2341e41f4b71Sopenharmony_ci| ------- | --------------------------- | ---- | ------------------------------------------- |
2342e41f4b71Sopenharmony_ci| handle  | number                      | Yes  | Handle for the **abortSession** operation.                        |
2343e41f4b71Sopenharmony_ci| options | [HuksOptions](#huksoptions) | Yes  | Parameter set used for the **abortSession** operation.                      |
2344e41f4b71Sopenharmony_ci
2345e41f4b71Sopenharmony_ci**Return value**
2346e41f4b71Sopenharmony_ci
2347e41f4b71Sopenharmony_ci| Type                               | Description                                              |
2348e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
2349e41f4b71Sopenharmony_ci| Promise\<void>             | Promise used to return the **abortSession** operation result.|
2350e41f4b71Sopenharmony_ci
2351e41f4b71Sopenharmony_ci**Error codes**
2352e41f4b71Sopenharmony_ci
2353e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
2354e41f4b71Sopenharmony_ci
2355e41f4b71Sopenharmony_ci| ID| Error Message     |
2356e41f4b71Sopenharmony_ci| -------- | ------------- |
2357e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
2358e41f4b71Sopenharmony_ci| 801 | api is not supported. |
2359e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
2360e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
2361e41f4b71Sopenharmony_ci| 12000006 | error occurred in crypto engine. |
2362e41f4b71Sopenharmony_ci| 12000012 | external error. |
2363e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
2364e41f4b71Sopenharmony_ci
2365e41f4b71Sopenharmony_ci**Example**
2366e41f4b71Sopenharmony_ci
2367e41f4b71Sopenharmony_ci```ts
2368e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
2369e41f4b71Sopenharmony_ci/* huks.initSession, huks.updateSession, and huks.finishSession must be used together.
2370e41f4b71Sopenharmony_ci * If an error occurs in any of huks.initSession, huks.updateSession,
2371e41f4b71Sopenharmony_ci * and huks.finishSession operations,
2372e41f4b71Sopenharmony_ci * call huks.abortSession to terminate the use of the key.
2373e41f4b71Sopenharmony_ci *
2374e41f4b71Sopenharmony_ci * The following uses a 2048-bit RSA key as an example. The promise-based APIs are used.
2375e41f4b71Sopenharmony_ci */
2376e41f4b71Sopenharmony_ci
2377e41f4b71Sopenharmony_cifunction stringToUint8Array(str: string) {
2378e41f4b71Sopenharmony_ci    let arr: number[] = [];
2379e41f4b71Sopenharmony_ci    for (let i = 0, j = str.length; i < j; ++i) {
2380e41f4b71Sopenharmony_ci        arr.push(str.charCodeAt(i));
2381e41f4b71Sopenharmony_ci    }
2382e41f4b71Sopenharmony_ci    let tmpUint8Array = new Uint8Array(arr);
2383e41f4b71Sopenharmony_ci    return tmpUint8Array;
2384e41f4b71Sopenharmony_ci}
2385e41f4b71Sopenharmony_ci
2386e41f4b71Sopenharmony_cilet keyAlias = "HuksDemoRSA";
2387e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = []
2388e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
2389e41f4b71Sopenharmony_ci    properties: properties,
2390e41f4b71Sopenharmony_ci    inData: new Uint8Array(0)
2391e41f4b71Sopenharmony_ci};
2392e41f4b71Sopenharmony_cilet handle: number = 0;
2393e41f4b71Sopenharmony_ci
2394e41f4b71Sopenharmony_ciasync function generateKey() {
2395e41f4b71Sopenharmony_ci    properties[0] = {
2396e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
2397e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_RSA
2398e41f4b71Sopenharmony_ci    };
2399e41f4b71Sopenharmony_ci    properties[1] = {
2400e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
2401e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048
2402e41f4b71Sopenharmony_ci    };
2403e41f4b71Sopenharmony_ci    properties[2] = {
2404e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
2405e41f4b71Sopenharmony_ci        value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT
2406e41f4b71Sopenharmony_ci    };
2407e41f4b71Sopenharmony_ci    properties[3] = {
2408e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PADDING,
2409e41f4b71Sopenharmony_ci        value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5
2410e41f4b71Sopenharmony_ci    };
2411e41f4b71Sopenharmony_ci    properties[4] = {
2412e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_DIGEST,
2413e41f4b71Sopenharmony_ci        value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
2414e41f4b71Sopenharmony_ci    };
2415e41f4b71Sopenharmony_ci    properties[5] = {
2416e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
2417e41f4b71Sopenharmony_ci        value: huks.HuksCipherMode.HUKS_MODE_ECB,
2418e41f4b71Sopenharmony_ci    }
2419e41f4b71Sopenharmony_ci
2420e41f4b71Sopenharmony_ci    try {
2421e41f4b71Sopenharmony_ci        await huks.generateKeyItem(keyAlias, options)
2422e41f4b71Sopenharmony_ci            .then((data) => {
2423e41f4b71Sopenharmony_ci                console.info(`promise: generateKeyItem success`);
2424e41f4b71Sopenharmony_ci            })
2425e41f4b71Sopenharmony_ci            .catch((error: Error) => {
2426e41f4b71Sopenharmony_ci                console.error(`promise: generateKeyItem failed`);
2427e41f4b71Sopenharmony_ci            });
2428e41f4b71Sopenharmony_ci    } catch (error) {
2429e41f4b71Sopenharmony_ci        console.error(`promise: generateKeyItem input arg invalid`);
2430e41f4b71Sopenharmony_ci    }
2431e41f4b71Sopenharmony_ci}
2432e41f4b71Sopenharmony_ci
2433e41f4b71Sopenharmony_ciasync function huksInit() {
2434e41f4b71Sopenharmony_ci    console.info('enter huksInit');
2435e41f4b71Sopenharmony_ci    try {
2436e41f4b71Sopenharmony_ci        await huks.initSession(keyAlias, options)
2437e41f4b71Sopenharmony_ci            .then((data) => {
2438e41f4b71Sopenharmony_ci                console.info(`promise: initSession success, data = ${JSON.stringify(data)}`);
2439e41f4b71Sopenharmony_ci                handle = data.handle;
2440e41f4b71Sopenharmony_ci            })
2441e41f4b71Sopenharmony_ci            .catch((error: Error) => {
2442e41f4b71Sopenharmony_ci                console.error(`promise: initSession key failed`);
2443e41f4b71Sopenharmony_ci            });
2444e41f4b71Sopenharmony_ci    } catch (error) {
2445e41f4b71Sopenharmony_ci        console.error(`promise: initSession input arg invalid`);
2446e41f4b71Sopenharmony_ci    }
2447e41f4b71Sopenharmony_ci}
2448e41f4b71Sopenharmony_ci
2449e41f4b71Sopenharmony_ciasync function huksUpdate() {
2450e41f4b71Sopenharmony_ci    console.info('enter huksUpdate');
2451e41f4b71Sopenharmony_ci    options.inData = stringToUint8Array("huksHmacTest");
2452e41f4b71Sopenharmony_ci    try {
2453e41f4b71Sopenharmony_ci        await huks.updateSession(handle, options)
2454e41f4b71Sopenharmony_ci            .then((data) => {
2455e41f4b71Sopenharmony_ci                console.info(`promise: updateSession success, data = ${JSON.stringify(data)}`);
2456e41f4b71Sopenharmony_ci            })
2457e41f4b71Sopenharmony_ci            .catch((error: Error) => {
2458e41f4b71Sopenharmony_ci                console.error(`promise: updateSession failed`);
2459e41f4b71Sopenharmony_ci            });
2460e41f4b71Sopenharmony_ci    } catch (error) {
2461e41f4b71Sopenharmony_ci        console.error(`promise: updateSession input arg invalid`);
2462e41f4b71Sopenharmony_ci    }
2463e41f4b71Sopenharmony_ci}
2464e41f4b71Sopenharmony_ci
2465e41f4b71Sopenharmony_ciasync function huksFinish() {
2466e41f4b71Sopenharmony_ci    console.info('enter huksFinish');
2467e41f4b71Sopenharmony_ci    options.inData = new Uint8Array(0);
2468e41f4b71Sopenharmony_ci    try {
2469e41f4b71Sopenharmony_ci        await huks.finishSession(handle, options)
2470e41f4b71Sopenharmony_ci            .then((data) => {
2471e41f4b71Sopenharmony_ci                console.info(`promise: finishSession success, data = ${JSON.stringify(data)}`);
2472e41f4b71Sopenharmony_ci            })
2473e41f4b71Sopenharmony_ci            .catch((error: Error) => {
2474e41f4b71Sopenharmony_ci                console.error(`promise: finishSession failed`);
2475e41f4b71Sopenharmony_ci            });
2476e41f4b71Sopenharmony_ci    } catch (error) {
2477e41f4b71Sopenharmony_ci        console.error(`promise: finishSession input arg invalid`);
2478e41f4b71Sopenharmony_ci    }
2479e41f4b71Sopenharmony_ci}
2480e41f4b71Sopenharmony_ci
2481e41f4b71Sopenharmony_ciasync function huksAbort() {
2482e41f4b71Sopenharmony_ci    console.info('enter huksAbort');
2483e41f4b71Sopenharmony_ci    try {
2484e41f4b71Sopenharmony_ci        await huks.abortSession(handle, options)
2485e41f4b71Sopenharmony_ci            .then((data) => {
2486e41f4b71Sopenharmony_ci                console.info(`promise: abortSession success`);
2487e41f4b71Sopenharmony_ci            })
2488e41f4b71Sopenharmony_ci            .catch((error: Error) => {
2489e41f4b71Sopenharmony_ci                console.error(`promise: abortSession failed`);
2490e41f4b71Sopenharmony_ci            });
2491e41f4b71Sopenharmony_ci    } catch (error) {
2492e41f4b71Sopenharmony_ci        console.error(`promise: abortSession input arg invalid`);
2493e41f4b71Sopenharmony_ci    }
2494e41f4b71Sopenharmony_ci}
2495e41f4b71Sopenharmony_ci
2496e41f4b71Sopenharmony_ciasync function testAbort() {
2497e41f4b71Sopenharmony_ci    await generateKey();
2498e41f4b71Sopenharmony_ci    await huksInit(); // Use abortSession to abort initSession.
2499e41f4b71Sopenharmony_ci    await huksAbort();
2500e41f4b71Sopenharmony_ci}
2501e41f4b71Sopenharmony_ci```
2502e41f4b71Sopenharmony_ci
2503e41f4b71Sopenharmony_ci## huks.listAliases<sup>12+</sup>
2504e41f4b71Sopenharmony_ci
2505e41f4b71Sopenharmony_cilistAliases(options: HuksOptions): Promise\<HuksListAliasesReturnResult>;
2506e41f4b71Sopenharmony_ci
2507e41f4b71Sopenharmony_ciLists key aliases. This API uses a promise to return the result.
2508e41f4b71Sopenharmony_ci
2509e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2510e41f4b71Sopenharmony_ci
2511e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2512e41f4b71Sopenharmony_ci
2513e41f4b71Sopenharmony_ci**Parameters**
2514e41f4b71Sopenharmony_ci
2515e41f4b71Sopenharmony_ci| Name | Type                       | Mandatory| Description                                       |
2516e41f4b71Sopenharmony_ci| ------- | --------------------------- | ---- | ------------------------------------------- |
2517e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)                      | Yes  | Parameters for listing key aliases.                        |
2518e41f4b71Sopenharmony_ci
2519e41f4b71Sopenharmony_ci
2520e41f4b71Sopenharmony_ci**Return value**
2521e41f4b71Sopenharmony_ci
2522e41f4b71Sopenharmony_ci| Type                               | Description                                              |
2523e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
2524e41f4b71Sopenharmony_ci| Promise<[HuksListAliasesReturnResult](#hukslistaliasesreturnresult12)> | Promise used to return the key aliases obtained.|
2525e41f4b71Sopenharmony_ci
2526e41f4b71Sopenharmony_ci**Error codes**
2527e41f4b71Sopenharmony_ci
2528e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
2529e41f4b71Sopenharmony_ci
2530e41f4b71Sopenharmony_ci| ID| Error Message     |
2531e41f4b71Sopenharmony_ci| -------- | ------------- |
2532e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
2533e41f4b71Sopenharmony_ci| 12000004 | operating file failed. |
2534e41f4b71Sopenharmony_ci| 12000005 | IPC communication failed. |
2535e41f4b71Sopenharmony_ci| 12000012 | external error. |
2536e41f4b71Sopenharmony_ci| 12000014 | memory is insufficient. |
2537e41f4b71Sopenharmony_ci
2538e41f4b71Sopenharmony_ci**Example**
2539e41f4b71Sopenharmony_ci
2540e41f4b71Sopenharmony_ci```ts
2541e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit'
2542e41f4b71Sopenharmony_ci
2543e41f4b71Sopenharmony_ciasync function testListAliases() {
2544e41f4b71Sopenharmony_ci  let queryProperties: Array<huks.HuksParam> = [
2545e41f4b71Sopenharmony_ci    {
2546e41f4b71Sopenharmony_ci      tag: huks.HuksTag.HUKS_TAG_AUTH_STORAGE_LEVEL,
2547e41f4b71Sopenharmony_ci      value: huks.HuksAuthStorageLevel.HUKS_AUTH_STORAGE_LEVEL_DE
2548e41f4b71Sopenharmony_ci    }
2549e41f4b71Sopenharmony_ci  ];
2550e41f4b71Sopenharmony_ci  let queryOptions: huks.HuksOptions = {
2551e41f4b71Sopenharmony_ci    properties: queryProperties
2552e41f4b71Sopenharmony_ci  };
2553e41f4b71Sopenharmony_ci
2554e41f4b71Sopenharmony_ci  try {
2555e41f4b71Sopenharmony_ci    let result: huks.HuksListAliasesReturnResult = await huks.listAliases(queryOptions);
2556e41f4b71Sopenharmony_ci    console.info(`promise: listAliases success`);
2557e41f4b71Sopenharmony_ci  } catch (error) {
2558e41f4b71Sopenharmony_ci    console.error(`promise: listAliases fail , code: ` + error.code + `, msg: ` + error.message);
2559e41f4b71Sopenharmony_ci  }
2560e41f4b71Sopenharmony_ci}
2561e41f4b71Sopenharmony_ci
2562e41f4b71Sopenharmony_ci```
2563e41f4b71Sopenharmony_ci
2564e41f4b71Sopenharmony_ci
2565e41f4b71Sopenharmony_ci## HuksExceptionErrCode<sup>9+</sup>
2566e41f4b71Sopenharmony_ci
2567e41f4b71Sopenharmony_ciEnumerates the error codes.
2568e41f4b71Sopenharmony_ci
2569e41f4b71Sopenharmony_ciFor details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
2570e41f4b71Sopenharmony_ci
2571e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2572e41f4b71Sopenharmony_ci
2573e41f4b71Sopenharmony_ci| Name                                          | Value|  Description                       |
2574e41f4b71Sopenharmony_ci| ---------------------------------------------- | -------- |--------------------------- |
2575e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_PERMISSION_FAIL                  | 201      | Permission verification failed.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core         |
2576e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_NOT_SYSTEM_APP<sup>12+</sup>     | 202      | The caller is not a system application and cannot call the system API.<br> **System capability**: SystemCapability.Security.Huks.Core              |
2577e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_ILLEGAL_ARGUMENT                 | 401      | Invalid parameters are detected. Possible causes: 1. Mandatory parameters are left unspecified.2. Incorrect parameter types.3. Parameter verification failed.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core         |
2578e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_NOT_SUPPORTED_API                | 801      | The API is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core              |
2579e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_FEATURE_NOT_SUPPORTED            | 12000001 | The feature is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core        |
2580e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT      | 12000002 | Key algorithm parameters are missing.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core         |
2581e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT      | 12000003 | Invalid key algorithm parameters are detected.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core         |
2582e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_FILE_OPERATION_FAIL              | 12000004 | The file operation failed.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core             |
2583e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_COMMUNICATION_FAIL               | 12000005 | The communication failed.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core                 |
2584e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_CRYPTO_FAIL                      | 12000006 | Failed to operate the algorithm library.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core           |
2585e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_KEY_AUTH_PERMANENTLY_INVALIDATED | 12000007 | Failed to access the key because the key has expired.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2586e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_KEY_AUTH_VERIFY_FAILED           | 12000008 | Failed to access the key because the authentication has failed.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2587e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_KEY_AUTH_TIME_OUT                | 12000009 | Key access timed out.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2588e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_SESSION_LIMIT                    | 12000010 | The number of key operation sessions has reached the limit.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core   |
2589e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_ITEM_NOT_EXIST                   | 12000011 | The target object does not exist.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core           |
2590e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_EXTERNAL_ERROR                   | 12000012 | An external error occurs.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core                 |
2591e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_CREDENTIAL_NOT_EXIST             | 12000013 | The credential does not exist.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core             |
2592e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_INSUFFICIENT_MEMORY              | 12000014 | The memory is insufficient.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core                 |
2593e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_CALL_SERVICE_FAILED              | 12000015 | Failed to call other system services.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core     |
2594e41f4b71Sopenharmony_ci| HUKS_ERR_CODE_DEVICE_PASSWORD_UNSET<sup>11+</sup>  | 12000016 | The required lock screen password is not set.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension    |
2595e41f4b71Sopenharmony_ci
2596e41f4b71Sopenharmony_ci## HuksKeyPurpose
2597e41f4b71Sopenharmony_ci
2598e41f4b71Sopenharmony_ciEnumerates the key purposes.
2599e41f4b71Sopenharmony_ci
2600e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2601e41f4b71Sopenharmony_ci
2602e41f4b71Sopenharmony_ci| Name                    | Value  | Description                            |
2603e41f4b71Sopenharmony_ci| ------------------------ | ---- | -------------------------------- |
2604e41f4b71Sopenharmony_ci| HUKS_KEY_PURPOSE_ENCRYPT | 1    | Used to encrypt the plaintext.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2605e41f4b71Sopenharmony_ci| HUKS_KEY_PURPOSE_DECRYPT | 2    | Used to decrypt the cipher text.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2606e41f4b71Sopenharmony_ci| HUKS_KEY_PURPOSE_SIGN    | 4    | Used for signing.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2607e41f4b71Sopenharmony_ci| HUKS_KEY_PURPOSE_VERIFY  | 8    | Used to verify the signature.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2608e41f4b71Sopenharmony_ci| HUKS_KEY_PURPOSE_DERIVE  | 16   | Used to derive a key.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2609e41f4b71Sopenharmony_ci| HUKS_KEY_PURPOSE_WRAP    | 32   | Used for an encrypted export.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2610e41f4b71Sopenharmony_ci| HUKS_KEY_PURPOSE_UNWRAP  | 64   | Used for an encrypted import.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2611e41f4b71Sopenharmony_ci| HUKS_KEY_PURPOSE_MAC     | 128  | Used to generate a message authentication code (MAC).<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2612e41f4b71Sopenharmony_ci| HUKS_KEY_PURPOSE_AGREE   | 256  | Used for key agreement.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2613e41f4b71Sopenharmony_ci
2614e41f4b71Sopenharmony_ci## HuksKeyDigest
2615e41f4b71Sopenharmony_ci
2616e41f4b71Sopenharmony_ciEnumerates the digest algorithms.
2617e41f4b71Sopenharmony_ci
2618e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2619e41f4b71Sopenharmony_ci
2620e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2621e41f4b71Sopenharmony_ci
2622e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 8 to 11, and **SystemCapability.Security.Huks.Core** since API version 12.
2623e41f4b71Sopenharmony_ci
2624e41f4b71Sopenharmony_ci| Name                  | Value  | Description                                    |
2625e41f4b71Sopenharmony_ci| ---------------------- | ---- | ---------------------------------------- |
2626e41f4b71Sopenharmony_ci| HUKS_DIGEST_NONE       | 0   | No digest algorithm<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2627e41f4b71Sopenharmony_ci| HUKS_DIGEST_MD5        | 1    | MD5<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2628e41f4b71Sopenharmony_ci| HUKS_DIGEST_SM3<sup>9+</sup> | 2 | SM3<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>9-11</sup>|
2629e41f4b71Sopenharmony_ci| HUKS_DIGEST_SHA1       | 10   | SHA-1<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2630e41f4b71Sopenharmony_ci| HUKS_DIGEST_SHA224 | 11   | SHA-224<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2631e41f4b71Sopenharmony_ci| HUKS_DIGEST_SHA256 | 12  | SHA-256<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2632e41f4b71Sopenharmony_ci| HUKS_DIGEST_SHA384  | 13  | SHA-384<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2633e41f4b71Sopenharmony_ci| HUKS_DIGEST_SHA512 | 14  | SHA-512<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2634e41f4b71Sopenharmony_ci
2635e41f4b71Sopenharmony_ci## HuksKeyPadding
2636e41f4b71Sopenharmony_ci
2637e41f4b71Sopenharmony_ciEnumerates the padding algorithms.
2638e41f4b71Sopenharmony_ci
2639e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2640e41f4b71Sopenharmony_ci
2641e41f4b71Sopenharmony_ci| Name                  | Value  | Description                                    |
2642e41f4b71Sopenharmony_ci| ---------------------- | ---- | ---------------------------------------- |
2643e41f4b71Sopenharmony_ci| HUKS_PADDING_NONE | 0    | No padding algorithm is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2644e41f4b71Sopenharmony_ci| HUKS_PADDING_OAEP | 1    | Optimal Asymmetric Encryption Padding (OAEP).<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2645e41f4b71Sopenharmony_ci| HUKS_PADDING_PSS | 2    | Probabilistic Signature Scheme (PSS).<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2646e41f4b71Sopenharmony_ci| HUKS_PADDING_PKCS1_V1_5 | 3    | Public Key Cryptography Standards (PKCS) #1 v1.5.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2647e41f4b71Sopenharmony_ci| HUKS_PADDING_PKCS5 | 4   | PKCS #5.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2648e41f4b71Sopenharmony_ci| HUKS_PADDING_PKCS7 | 5   | PKCS #7.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2649e41f4b71Sopenharmony_ci| HUKS_PADDING_ISO_IEC_9796_2<sup>12+</sup> | 6   | ISO/IEC 9796-2, which is not supported currently.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2650e41f4b71Sopenharmony_ci| HUKS_PADDING_ISO_IEC_9797_1<sup>12+</sup>  | 7   | ISO/IEC 9796-1, which is not supported currently.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2651e41f4b71Sopenharmony_ci
2652e41f4b71Sopenharmony_ci## HuksCipherMode
2653e41f4b71Sopenharmony_ci
2654e41f4b71Sopenharmony_ciEnumerates the cipher modes.
2655e41f4b71Sopenharmony_ci
2656e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2657e41f4b71Sopenharmony_ci
2658e41f4b71Sopenharmony_ci| Name         | Value  | Description                 |
2659e41f4b71Sopenharmony_ci| ------------- | ---- | --------------------- |
2660e41f4b71Sopenharmony_ci| HUKS_MODE_ECB | 1    | Electronic Code Block (ECB) mode<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2661e41f4b71Sopenharmony_ci| HUKS_MODE_CBC | 2    | Cipher Block Chaining (CBC) mode<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2662e41f4b71Sopenharmony_ci| HUKS_MODE_CTR | 3    | Counter (CTR) mode<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2663e41f4b71Sopenharmony_ci| HUKS_MODE_OFB | 4    | Output Feedback (OFB) mode<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2664e41f4b71Sopenharmony_ci| HUKS_MODE_CFB<sup>12+</sup> | 5    | Ciphertext Feedback (CFB) mode<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2665e41f4b71Sopenharmony_ci| HUKS_MODE_CCM | 31   | Counter with CBC-MAC (CCM) mode<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2666e41f4b71Sopenharmony_ci| HUKS_MODE_GCM | 32   | Galois/Counter (GCM) mode<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2667e41f4b71Sopenharmony_ci
2668e41f4b71Sopenharmony_ci## HuksKeySize
2669e41f4b71Sopenharmony_ci
2670e41f4b71Sopenharmony_ciEnumerates the key sizes.
2671e41f4b71Sopenharmony_ci
2672e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2673e41f4b71Sopenharmony_ci
2674e41f4b71Sopenharmony_ci| Name                              | Value  | Description                                      |
2675e41f4b71Sopenharmony_ci| ---------------------------------- | ---- | ------------------------------------------ |
2676e41f4b71Sopenharmony_ci| HUKS_RSA_KEY_SIZE_512              | 512  | Rivest-Shamir-Adleman (RSA) key of 512 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2677e41f4b71Sopenharmony_ci| HUKS_RSA_KEY_SIZE_768              | 768  | RSA key of 768 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2678e41f4b71Sopenharmony_ci| HUKS_RSA_KEY_SIZE_1024             | 1024 | RSA key of 1024 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2679e41f4b71Sopenharmony_ci| HUKS_RSA_KEY_SIZE_2048             | 2048 | RSA key of 2048 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2680e41f4b71Sopenharmony_ci| HUKS_RSA_KEY_SIZE_3072             | 3072 | RSA key of 3072 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2681e41f4b71Sopenharmony_ci| HUKS_RSA_KEY_SIZE_4096             | 4096 | RSA key of 4096 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2682e41f4b71Sopenharmony_ci| HUKS_ECC_KEY_SIZE_224              | 224  | Elliptic Curve Cryptography (ECC) key of 224 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2683e41f4b71Sopenharmony_ci| HUKS_ECC_KEY_SIZE_256              | 256  | ECC key of 256 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2684e41f4b71Sopenharmony_ci| HUKS_ECC_KEY_SIZE_384              | 384  | ECC key of 384 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2685e41f4b71Sopenharmony_ci| HUKS_ECC_KEY_SIZE_521              | 521  | ECC key of 521 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2686e41f4b71Sopenharmony_ci| HUKS_AES_KEY_SIZE_128              | 128  | Advanced Encryption Standard (AES) key of 128 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2687e41f4b71Sopenharmony_ci| HUKS_AES_KEY_SIZE_192              | 192  | AES key of 192 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2688e41f4b71Sopenharmony_ci| HUKS_AES_KEY_SIZE_256              | 256  | AES key of 256 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2689e41f4b71Sopenharmony_ci| HUKS_AES_KEY_SIZE_512<sup>(deprecated)</sup>              | 512  | AES key of 512 bits This API is deprecated since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2690e41f4b71Sopenharmony_ci| HUKS_CURVE25519_KEY_SIZE_256       | 256  | Curve25519 key of 256 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2691e41f4b71Sopenharmony_ci| HUKS_DH_KEY_SIZE_2048              | 2048 | Diffie-Hellman (DH) key of 2048 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2692e41f4b71Sopenharmony_ci| HUKS_DH_KEY_SIZE_3072              | 3072 | DH key of 3072 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2693e41f4b71Sopenharmony_ci| HUKS_DH_KEY_SIZE_4096              | 4096 | DH key of 4096 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2694e41f4b71Sopenharmony_ci| HUKS_SM2_KEY_SIZE_256<sup>9+</sup> | 256  | ShangMi2 (SM2) key of 256 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>9-11</sup>|
2695e41f4b71Sopenharmony_ci| HUKS_SM4_KEY_SIZE_128<sup>9+</sup> | 128  | ShangMi4 (SM4) key of 128 bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>9-11</sup>|
2696e41f4b71Sopenharmony_ci| HUKS_DES_KEY_SIZE_64<sup>12+</sup>  | 64  | DES key of 64 bits. This value is not supported currently.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2697e41f4b71Sopenharmony_ci| HUKS_3DES_KEY_SIZE_128<sup>12+</sup>  | 128  | 3DES key of 128 bits. This value is not supported currently.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2698e41f4b71Sopenharmony_ci| HUKS_3DES_KEY_SIZE_192<sup>12+</sup>  | 192  | 3DES key of 192 bits. This value is not supported currently.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2699e41f4b71Sopenharmony_ci
2700e41f4b71Sopenharmony_ci## HuksKeyAlg
2701e41f4b71Sopenharmony_ci
2702e41f4b71Sopenharmony_ciEnumerates the key algorithms.
2703e41f4b71Sopenharmony_ci
2704e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2705e41f4b71Sopenharmony_ci
2706e41f4b71Sopenharmony_ci| Name                     | Value  | Description                 |
2707e41f4b71Sopenharmony_ci| ------------------------- | ---- | --------------------- |
2708e41f4b71Sopenharmony_ci| HUKS_ALG_RSA              | 1    | RSA.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2709e41f4b71Sopenharmony_ci| HUKS_ALG_ECC              | 2    | ECC.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2710e41f4b71Sopenharmony_ci| HUKS_ALG_DSA              | 3    | DSA.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2711e41f4b71Sopenharmony_ci| HUKS_ALG_AES              | 20   | AES.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2712e41f4b71Sopenharmony_ci| HUKS_ALG_HMAC             | 50   | HMAC.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2713e41f4b71Sopenharmony_ci| HUKS_ALG_HKDF             | 51   | HKDF.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2714e41f4b71Sopenharmony_ci| HUKS_ALG_PBKDF2           | 52   | PBKDF2.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2715e41f4b71Sopenharmony_ci| HUKS_ALG_ECDH             | 100  | ECDH.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2716e41f4b71Sopenharmony_ci| HUKS_ALG_X25519           | 101  | X25519. <br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2717e41f4b71Sopenharmony_ci| HUKS_ALG_ED25519          | 102  | Ed25519.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2718e41f4b71Sopenharmony_ci| HUKS_ALG_DH               | 103  | DH.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2719e41f4b71Sopenharmony_ci| HUKS_ALG_SM2<sup>9+</sup> | 150  | SM2.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>9-11</sup>|
2720e41f4b71Sopenharmony_ci| HUKS_ALG_SM3<sup>9+</sup> | 151  | SM3.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>9-11</sup>|
2721e41f4b71Sopenharmony_ci| HUKS_ALG_SM4<sup>9+</sup> | 152  | SM4.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>9-11</sup>|
2722e41f4b71Sopenharmony_ci| HUKS_ALG_DES<sup>12+</sup> | 160  | DES, which is not supported currently.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2723e41f4b71Sopenharmony_ci| HUKS_ALG_3DES<sup>12+</sup> | 161  | 3DES, which is not supported currently.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2724e41f4b71Sopenharmony_ci| HUKS_ALG_CMAC<sup>12+</sup> | 162  | CMAC, which is not supported currently.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2725e41f4b71Sopenharmony_ci
2726e41f4b71Sopenharmony_ci## HuksKeyGenerateType
2727e41f4b71Sopenharmony_ci
2728e41f4b71Sopenharmony_ciEnumerates the key generation types.
2729e41f4b71Sopenharmony_ci
2730e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2731e41f4b71Sopenharmony_ci
2732e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2733e41f4b71Sopenharmony_ci
2734e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 8 to 11, and **SystemCapability.Security.Huks.Core** since API version 12.
2735e41f4b71Sopenharmony_ci
2736e41f4b71Sopenharmony_ci| Name                          | Value  | Description            |
2737e41f4b71Sopenharmony_ci| ------------------------------ | ---- | ---------------- |
2738e41f4b71Sopenharmony_ci| HUKS_KEY_GENERATE_TYPE_DEFAULT | 0    | Key generated by default.|
2739e41f4b71Sopenharmony_ci| HUKS_KEY_GENERATE_TYPE_DERIVE  | 1    | Derived key.|
2740e41f4b71Sopenharmony_ci| HUKS_KEY_GENERATE_TYPE_AGREE   | 2    | Key generated by agreement.|
2741e41f4b71Sopenharmony_ci
2742e41f4b71Sopenharmony_ci## HuksKeyFlag
2743e41f4b71Sopenharmony_ci
2744e41f4b71Sopenharmony_ciEnumerates the key generation modes.
2745e41f4b71Sopenharmony_ci
2746e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2747e41f4b71Sopenharmony_ci
2748e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2749e41f4b71Sopenharmony_ci
2750e41f4b71Sopenharmony_ci| Name                      | Value  | Description                                |
2751e41f4b71Sopenharmony_ci| -------------------------- | ---- | ------------------------------------ |
2752e41f4b71Sopenharmony_ci| HUKS_KEY_FLAG_IMPORT_KEY   | 1    | Import a key using an API.    |
2753e41f4b71Sopenharmony_ci| HUKS_KEY_FLAG_GENERATE_KEY | 2    | Generate a key by using an API.    |
2754e41f4b71Sopenharmony_ci| HUKS_KEY_FLAG_AGREE_KEY    | 3    | Generate a key by using a key agreement API.|
2755e41f4b71Sopenharmony_ci| HUKS_KEY_FLAG_DERIVE_KEY   | 4    | Derive a key by using an API.|
2756e41f4b71Sopenharmony_ci
2757e41f4b71Sopenharmony_ci## HuksKeyStorageType
2758e41f4b71Sopenharmony_ci
2759e41f4b71Sopenharmony_ciEnumerates the key storage modes.
2760e41f4b71Sopenharmony_ci
2761e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2762e41f4b71Sopenharmony_ci
2763e41f4b71Sopenharmony_ci| Name                                         | Value  | Description                          |
2764e41f4b71Sopenharmony_ci| --------------------------------------------  | ---- | ------------------------------ |
2765e41f4b71Sopenharmony_ci| HUKS_STORAGE_TEMP<sup>(deprecated)</sup>      | 0    | The key is managed locally.<br>**NOTE**<br>This tag is deprecated since API version 10. No substitute is provided because this tag is not used in key management. In key derivation scenarios, use **HUKS_STORAGE_ONLY_USED_IN_HUKS** or **HUKS_STORAGE_KEY_EXPORT_ALLOWED**.<br> **System capability**: SystemCapability.Security.Huks.Core|
2766e41f4b71Sopenharmony_ci| HUKS_STORAGE_PERSISTENT<sup>(deprecated)</sup>      | 1    | The key is managed by the HUKS service.<br>NOTE<br>This tag is deprecated since API version 10. No substitute is provided because this tag is not used in key management. In key derivation scenarios, use **HUKS_STORAGE_ONLY_USED_IN_HUKS** or **HUKS_STORAGE_KEY_EXPORT_ALLOWED**.<br> **System capability**: SystemCapability.Security.Huks.Core|
2767e41f4b71Sopenharmony_ci| HUKS_STORAGE_ONLY_USED_IN_HUKS<sup>10+</sup>  | 2    | The key derived from the master key is stored in the HUKS and managed by the HUKS.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>10-11</sup>|
2768e41f4b71Sopenharmony_ci| HUKS_STORAGE_KEY_EXPORT_ALLOWED<sup>10+</sup> | 3    | The key derived from the master key is exported to the service, and not managed by the HUKS.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>10-11</sup>|
2769e41f4b71Sopenharmony_ci
2770e41f4b71Sopenharmony_ci## HuksSendType
2771e41f4b71Sopenharmony_ci
2772e41f4b71Sopenharmony_ciEnumerates the tag transfer modes.
2773e41f4b71Sopenharmony_ci
2774e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2775e41f4b71Sopenharmony_ci
2776e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2777e41f4b71Sopenharmony_ci
2778e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 8 to 11, and **SystemCapability.Security.Huks.Core** since API version 12.
2779e41f4b71Sopenharmony_ci
2780e41f4b71Sopenharmony_ci| Name                | Value  | Description             |
2781e41f4b71Sopenharmony_ci| -------------------- | ---- | ----------------- |
2782e41f4b71Sopenharmony_ci| HUKS_SEND_TYPE_ASYNC | 0    | The tag is sent asynchronously.|
2783e41f4b71Sopenharmony_ci| HUKS_SEND_TYPE_SYNC  | 1    | The tag is sent synchronously.|
2784e41f4b71Sopenharmony_ci
2785e41f4b71Sopenharmony_ci## HuksUnwrapSuite<sup>9+</sup>
2786e41f4b71Sopenharmony_ci
2787e41f4b71Sopenharmony_ciEnumerates the algorithm suites that can be used for importing a key in ciphertext.
2788e41f4b71Sopenharmony_ci
2789e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2790e41f4b71Sopenharmony_ci
2791e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2792e41f4b71Sopenharmony_ci
2793e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 9 to 11, and **SystemCapability.Security.Huks.Core** since API version 12
2794e41f4b71Sopenharmony_ci
2795e41f4b71Sopenharmony_ci| Name                                          | Value  | Description                                                 |
2796e41f4b71Sopenharmony_ci| ---------------------------------------------- | ---- | ----------------------------------------------------- |
2797e41f4b71Sopenharmony_ci| HUKS_UNWRAP_SUITE_X25519_AES_256_GCM_NOPADDING | 1    | Use X25519 for key agreement and then use AES-256 GCM to encrypt the key.|
2798e41f4b71Sopenharmony_ci| HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING   | 2    | Use ECDH for key agreement and then use AES-256 GCM to encrypt the key.  |
2799e41f4b71Sopenharmony_ci
2800e41f4b71Sopenharmony_ci## HuksImportKeyType<sup>9+</sup>
2801e41f4b71Sopenharmony_ci
2802e41f4b71Sopenharmony_ciEnumerates the types of keys to import. By default, a public key is imported. This field is not required when a symmetric key is imported.
2803e41f4b71Sopenharmony_ci
2804e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2805e41f4b71Sopenharmony_ci
2806e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2807e41f4b71Sopenharmony_ci
2808e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 9 to 11, and **SystemCapability.Security.Huks.Core** since API version 12
2809e41f4b71Sopenharmony_ci
2810e41f4b71Sopenharmony_ci| Name                     | Value  | Description                          |
2811e41f4b71Sopenharmony_ci| ------------------------- | ---- | ------------------------------ |
2812e41f4b71Sopenharmony_ci| HUKS_KEY_TYPE_PUBLIC_KEY  | 0    | Public key    |
2813e41f4b71Sopenharmony_ci| HUKS_KEY_TYPE_PRIVATE_KEY | 1    | Private key    |
2814e41f4b71Sopenharmony_ci| HUKS_KEY_TYPE_KEY_PAIR    | 2    | Public and private key pair|
2815e41f4b71Sopenharmony_ci
2816e41f4b71Sopenharmony_ci## HuksRsaPssSaltLenType<sup>10+</sup>
2817e41f4b71Sopenharmony_ci
2818e41f4b71Sopenharmony_ciEnumerates the **salt_len** types to set when PSS padding is used in RSA signing or signature verification.
2819e41f4b71Sopenharmony_ci
2820e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2821e41f4b71Sopenharmony_ci
2822e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2823e41f4b71Sopenharmony_ci
2824e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API versions 10 to 11, and **SystemCapability.Security.Huks.Core** since API version 12.
2825e41f4b71Sopenharmony_ci
2826e41f4b71Sopenharmony_ci| Name                                      | Value  | Description                        |
2827e41f4b71Sopenharmony_ci| ------------------------------------------ | ---- | ---------------------------- |
2828e41f4b71Sopenharmony_ci| HUKS_RSA_PSS_SALT_LEN_DIGEST<sup>10+</sup> | 0    | **salt_len** is set to the digest length.|
2829e41f4b71Sopenharmony_ci| HUKS_RSA_PSS_SALT_LEN_MAX<sup>10+</sup>    | 1    | **salt_len** is set to the maximum length.|
2830e41f4b71Sopenharmony_ci
2831e41f4b71Sopenharmony_ci## HuksUserAuthType<sup>9+</sup>
2832e41f4b71Sopenharmony_ci
2833e41f4b71Sopenharmony_ciEnumerates the user authentication types.
2834e41f4b71Sopenharmony_ci
2835e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2836e41f4b71Sopenharmony_ci
2837e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2838e41f4b71Sopenharmony_ci
2839e41f4b71Sopenharmony_ci| Name                           | Value  | Description                     |
2840e41f4b71Sopenharmony_ci| ------------------------------- | ---- | ------------------------- |
2841e41f4b71Sopenharmony_ci| both.| 1 << 0 | Fingerprint authentication. |
2842e41f4b71Sopenharmony_ci| HUKS_USER_AUTH_TYPE_FACE        | 1 << 1 | Facial authentication.|
2843e41f4b71Sopenharmony_ci| HUKS_USER_AUTH_TYPE_PIN         | 1 << 2  | PIN authentication.|
2844e41f4b71Sopenharmony_ci
2845e41f4b71Sopenharmony_ci## HuksUserAuthMode<sup>12+</sup>
2846e41f4b71Sopenharmony_ci
2847e41f4b71Sopenharmony_ciEnumerates the user authentication modes.
2848e41f4b71Sopenharmony_ci
2849e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2850e41f4b71Sopenharmony_ci
2851e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2852e41f4b71Sopenharmony_ci
2853e41f4b71Sopenharmony_ci| Name                           | Value  | Description                     |
2854e41f4b71Sopenharmony_ci| ------------------------------- | ---- | ------------------------- |
2855e41f4b71Sopenharmony_ci| HUKS_USER_AUTH_MODE_LOCAL       | 0    | Local authentication.  |
2856e41f4b71Sopenharmony_ci| HUKS_USER_AUTH_MODE_COAUTH      | 1    | Cross-device collaborative authentication.|
2857e41f4b71Sopenharmony_ci
2858e41f4b71Sopenharmony_ci## HuksAuthAccessType<sup>9+</sup>
2859e41f4b71Sopenharmony_ci
2860e41f4b71Sopenharmony_ciEnumerates the access control types.
2861e41f4b71Sopenharmony_ci
2862e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2863e41f4b71Sopenharmony_ci
2864e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2865e41f4b71Sopenharmony_ci
2866e41f4b71Sopenharmony_ci| Name                                   | Value  | Description                                            |
2867e41f4b71Sopenharmony_ci| --------------------------------------- | ---- | ------------------------------------------------ |
2868e41f4b71Sopenharmony_ci| HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD | 1 << 0 | The key becomes invalid after the password is cleared.      |
2869e41f4b71Sopenharmony_ci| HUKS_AUTH_ACCESS_INVALID_NEW_BIO_ENROLL | 1 << 1 | The key becomes invalid after a new biometric feature is added.|
2870e41f4b71Sopenharmony_ci| HUKS_AUTH_ACCESS_ALWAYS_VALID<sup>11+</sup> | 1 << 2 | The key is always valid.|
2871e41f4b71Sopenharmony_ci
2872e41f4b71Sopenharmony_ci## HuksChallengeType<sup>9+</sup>
2873e41f4b71Sopenharmony_ci
2874e41f4b71Sopenharmony_ciEnumerates the types of the challenges generated when a key is used.
2875e41f4b71Sopenharmony_ci
2876e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2877e41f4b71Sopenharmony_ci
2878e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2879e41f4b71Sopenharmony_ci
2880e41f4b71Sopenharmony_ci| Name                           | Value  | Description                          |
2881e41f4b71Sopenharmony_ci| ------------------------------- | ---- | ------------------------------ |
2882e41f4b71Sopenharmony_ci| HUKS_CHALLENGE_TYPE_NORMAL | 0    | Normal challenge, which is of 32 bytes by default.|
2883e41f4b71Sopenharmony_ci| HUKS_CHALLENGE_TYPE_CUSTOM        | 1    | Custom challenge, which supports only one authentication for multiple keys.|
2884e41f4b71Sopenharmony_ci| HUKS_CHALLENGE_TYPE_NONE         | 2    | Challenge is not required.|
2885e41f4b71Sopenharmony_ci
2886e41f4b71Sopenharmony_ci## HuksChallengePosition<sup>9+</sup>
2887e41f4b71Sopenharmony_ci
2888e41f4b71Sopenharmony_ciEnumerates the positions of the 8-byte valid value in a custom challenge generated.
2889e41f4b71Sopenharmony_ci
2890e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2891e41f4b71Sopenharmony_ci
2892e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2893e41f4b71Sopenharmony_ci
2894e41f4b71Sopenharmony_ci| Name                           | Value  | Description                          |
2895e41f4b71Sopenharmony_ci| ------------------------------- | ---- | ------------------------------ |
2896e41f4b71Sopenharmony_ci| HUKS_CHALLENGE_POS_0 | 0    | Bytes 0 to 7.|
2897e41f4b71Sopenharmony_ci| HUKS_CHALLENGE_POS_1        | 1    | Bytes 8 to 15.|
2898e41f4b71Sopenharmony_ci| HUKS_CHALLENGE_POS_2         | 2    | Bytes 16 to 23.|
2899e41f4b71Sopenharmony_ci| HUKS_CHALLENGE_POS_3        | 3   | Bytes 24 to 31.|
2900e41f4b71Sopenharmony_ci
2901e41f4b71Sopenharmony_ci## HuksSecureSignType<sup>9+</sup>
2902e41f4b71Sopenharmony_ci
2903e41f4b71Sopenharmony_ciDefines the signature type of the key generated or imported.
2904e41f4b71Sopenharmony_ci
2905e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2906e41f4b71Sopenharmony_ci
2907e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
2908e41f4b71Sopenharmony_ci
2909e41f4b71Sopenharmony_ci| Name                          | Value  | Description                                                        |
2910e41f4b71Sopenharmony_ci| ------------------------------ | ---- | ------------------------------------------------------------ |
2911e41f4b71Sopenharmony_ci| HUKS_SECURE_SIGN_WITH_AUTHINFO | 1    | The signature carries authentication information. This field is specified when a key is generated or imported. When the key is used for signing, the data will be added with the authentication information and then be signed.|
2912e41f4b71Sopenharmony_ci
2913e41f4b71Sopenharmony_ci## HuksAuthStorageLevel<sup>11+</sup>
2914e41f4b71Sopenharmony_ci
2915e41f4b71Sopenharmony_ciRepresents the storage security level of a key.
2916e41f4b71Sopenharmony_ci
2917e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2918e41f4b71Sopenharmony_ci
2919e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2920e41f4b71Sopenharmony_ci
2921e41f4b71Sopenharmony_ciThe system capability is **SystemCapability.Security.Huks.Extension** in API version 11, and **SystemCapability.Security.Huks.Core** since API version 12.
2922e41f4b71Sopenharmony_ci
2923e41f4b71Sopenharmony_ci| Name                          | Value  | Description                                                        |
2924e41f4b71Sopenharmony_ci| ------------------------------ | ---- | ------------------------------------------------------------ |
2925e41f4b71Sopenharmony_ci| HUKS_AUTH_STORAGE_LEVEL_DE | 0    | The key can be accessed only after the device is started.|
2926e41f4b71Sopenharmony_ci| HUKS_AUTH_STORAGE_LEVEL_CE | 1    | The key can be accessed only after the first unlock of the device.|
2927e41f4b71Sopenharmony_ci| HUKS_AUTH_STORAGE_LEVEL_ECE | 2    | The key can be accessed only when the device is unlocked.|
2928e41f4b71Sopenharmony_ci
2929e41f4b71Sopenharmony_ci## HuksTagType
2930e41f4b71Sopenharmony_ci
2931e41f4b71Sopenharmony_ciEnumerates the tag data types.
2932e41f4b71Sopenharmony_ci
2933e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2934e41f4b71Sopenharmony_ci
2935e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2936e41f4b71Sopenharmony_ci
2937e41f4b71Sopenharmony_ci| Name                 | Value     | Description                                   |
2938e41f4b71Sopenharmony_ci| --------------------- | ------- | --------------------------------------- |
2939e41f4b71Sopenharmony_ci| HUKS_TAG_TYPE_INVALID | 0 << 28 | Invalid tag type.                    |
2940e41f4b71Sopenharmony_ci| HUKS_TAG_TYPE_INT     | 1 << 28 | Number of the int type. |
2941e41f4b71Sopenharmony_ci| HUKS_TAG_TYPE_UINT    | 2 << 28 | Number of the uint type.|
2942e41f4b71Sopenharmony_ci| HUKS_TAG_TYPE_ULONG   | 3 << 28 | BigInt.          |
2943e41f4b71Sopenharmony_ci| HUKS_TAG_TYPE_BOOL    | 4 << 28 | Boolean.         |
2944e41f4b71Sopenharmony_ci| HUKS_TAG_TYPE_BYTES   | 5 << 28 | Uint8Array.      |
2945e41f4b71Sopenharmony_ci
2946e41f4b71Sopenharmony_ci## HuksTag
2947e41f4b71Sopenharmony_ci
2948e41f4b71Sopenharmony_ciEnumerates the tags used to invoke parameters.
2949e41f4b71Sopenharmony_ci
2950e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Core
2951e41f4b71Sopenharmony_ci
2952e41f4b71Sopenharmony_ci| Name                                                       | Value                                      | Description                                                        |
2953e41f4b71Sopenharmony_ci| ----------------------------------------------------------- | ---------------------------------------- | ------------------------------------------------------------ |
2954e41f4b71Sopenharmony_ci| HUKS_TAG_INVALID<sup>(deprecated)</sup>                     | HuksTagType.HUKS_TAG_TYPE_INVALID \| 0   | Invalid tag. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Core|
2955e41f4b71Sopenharmony_ci| HUKS_TAG_ALGORITHM                                          | HuksTagType.HUKS_TAG_TYPE_UINT \| 1      | Algorithm.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2956e41f4b71Sopenharmony_ci| HUKS_TAG_PURPOSE                                            | HuksTagType.HUKS_TAG_TYPE_UINT \| 2      | Purpose of the key.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2957e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_SIZE                                           | HuksTagType.HUKS_TAG_TYPE_UINT \| 3      | Key size.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2958e41f4b71Sopenharmony_ci| HUKS_TAG_DIGEST                                             | HuksTagType.HUKS_TAG_TYPE_UINT \| 4      | Digest algorithm.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2959e41f4b71Sopenharmony_ci| HUKS_TAG_PADDING                                            | HuksTagType.HUKS_TAG_TYPE_UINT \| 5      | Padding mode.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2960e41f4b71Sopenharmony_ci| HUKS_TAG_BLOCK_MODE                                         | HuksTagType.HUKS_TAG_TYPE_UINT \| 6      | Cipher mode.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2961e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_TYPE                                           | HuksTagType.HUKS_TAG_TYPE_UINT \| 7      | Key type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2962e41f4b71Sopenharmony_ci| HUKS_TAG_ASSOCIATED_DATA                                    | HuksTagType.HUKS_TAG_TYPE_BYTES \| 8     | Associated authentication data.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2963e41f4b71Sopenharmony_ci| HUKS_TAG_NONCE                                              | HuksTagType.HUKS_TAG_TYPE_BYTES \| 9     | Nonce for key encryption and decryption.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2964e41f4b71Sopenharmony_ci| HUKS_TAG_IV                                                 | HuksTagType.HUKS_TAG_TYPE_BYTES \| 10    | IV.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2965e41f4b71Sopenharmony_ci| HUKS_TAG_INFO                                               | HuksTagType.HUKS_TAG_TYPE_BYTES \| 11    | Information generated during key derivation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2966e41f4b71Sopenharmony_ci| HUKS_TAG_SALT                                               | HuksTagType.HUKS_TAG_TYPE_BYTES \| 12    | Salt value used for key derivation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2967e41f4b71Sopenharmony_ci| HUKS_TAG_PWD<sup>(deprecated)</sup>                         | HuksTagType.HUKS_TAG_TYPE_BYTES \| 13    | Password used for key derivation. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Core|
2968e41f4b71Sopenharmony_ci| HUKS_TAG_ITERATION                                          | HuksTagType.HUKS_TAG_TYPE_UINT \| 14     | Number of iterations for key derivation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2969e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_GENERATE_TYPE                                  | HuksTagType.HUKS_TAG_TYPE_UINT \| 15     | Key generation type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
2970e41f4b71Sopenharmony_ci| HUKS_TAG_DERIVE_MAIN_KEY<sup>(deprecated)</sup>             | HuksTagType.HUKS_TAG_TYPE_BYTES \| 16    | Main key for key derivation. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2971e41f4b71Sopenharmony_ci| HUKS_TAG_DERIVE_FACTOR<sup>(deprecated)</sup>               | HuksTagType.HUKS_TAG_TYPE_BYTES \| 17    | Factor for key derivation. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2972e41f4b71Sopenharmony_ci| HUKS_TAG_DERIVE_ALG<sup>(deprecated)</sup>                  | HuksTagType.HUKS_TAG_TYPE_UINT \| 18     | Type of the algorithm used for key derivation. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2973e41f4b71Sopenharmony_ci| HUKS_TAG_AGREE_ALG                                          | HuksTagType.HUKS_TAG_TYPE_UINT \| 19     | Type of the algorithm used for key agreement.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2974e41f4b71Sopenharmony_ci| HUKS_TAG_AGREE_PUBLIC_KEY_IS_KEY_ALIAS                      | HuksTagType.HUKS_TAG_TYPE_BOOL \| 20     | Public key alias used in key agreement.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2975e41f4b71Sopenharmony_ci| HUKS_TAG_AGREE_PRIVATE_KEY_ALIAS                            | HuksTagType.HUKS_TAG_TYPE_BYTES \| 21    | Private key alias used in key agreement.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2976e41f4b71Sopenharmony_ci| HUKS_TAG_AGREE_PUBLIC_KEY                                   | HuksTagType.HUKS_TAG_TYPE_BYTES \| 22    | Public key used in key agreement.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2977e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_ALIAS                                          | HuksTagType.HUKS_TAG_TYPE_BYTES \| 23    | Key alias.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
2978e41f4b71Sopenharmony_ci| HUKS_TAG_DERIVE_KEY_SIZE                                    | HuksTagType.HUKS_TAG_TYPE_UINT \| 24     | Size of the derived key.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2979e41f4b71Sopenharmony_ci| HUKS_TAG_IMPORT_KEY_TYPE<sup>9+</sup>                       | HuksTagType.HUKS_TAG_TYPE_UINT \| 25     | Type of the imported key.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>9-11</sup>|
2980e41f4b71Sopenharmony_ci| HUKS_TAG_UNWRAP_ALGORITHM_SUITE<sup>9+</sup>                | HuksTagType.HUKS_TAG_TYPE_UINT \| 26     | Algorithm suite required for encrypted imports.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>9-11</sup>|
2981e41f4b71Sopenharmony_ci| HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG<sup>10+</sup>      | HuksTagType.HUKS_TAG_TYPE_UINT \|29      | Storage type of the derived key or agreed key.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>10-11</sup>|
2982e41f4b71Sopenharmony_ci| HUKS_TAG_RSA_PSS_SALT_LEN_TYPE<sup>10+</sup>                | HuksTagType.HUKS_TAG_TYPE_UINT \|30      | Type of the **rsa_pss_salt_length**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>10-11</sup>|
2983e41f4b71Sopenharmony_ci| HUKS_TAG_ACTIVE_DATETIME<sup>(deprecated)</sup>             | HuksTagType.HUKS_TAG_TYPE_ULONG \| 201   | Parameter originally reserved for certificate management. It is deprecated because certificate management is no longer implemented in this module.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2984e41f4b71Sopenharmony_ci| HUKS_TAG_ORIGINATION_EXPIRE_DATETIME<sup>(deprecated)</sup> | HuksTagType.HUKS_TAG_TYPE_ULONG \| 202   | Parameter originally reserved for certificate management. It is deprecated because certificate management is no longer implemented in this module.<br> **System capability**: SystemCapability.Security.Huks.Core|
2985e41f4b71Sopenharmony_ci| HUKS_TAG_USAGE_EXPIRE_DATETIME<sup>(deprecated)</sup>       | HuksTagType.HUKS_TAG_TYPE_ULONG \| 203   | Parameter originally reserved for certificate management. It is deprecated because certificate management is no longer implemented in this module.<br> **System capability**: SystemCapability.Security.Huks.Core|
2986e41f4b71Sopenharmony_ci| HUKS_TAG_CREATION_DATETIME<sup>(deprecated)</sup>           | HuksTagType.HUKS_TAG_TYPE_ULONG \| 204   | Parameter originally reserved for certificate management. It is deprecated because certificate management is no longer implemented in this module.<br> **System capability**: SystemCapability.Security.Huks.Core|
2987e41f4b71Sopenharmony_ci| HUKS_TAG_ALL_USERS                                          | HuksTagType.HUKS_TAG_TYPE_BOOL \| 301    | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2988e41f4b71Sopenharmony_ci| HUKS_TAG_USER_ID                                            | HuksTagType.HUKS_TAG_TYPE_UINT \| 302    | ID of the user to which the key belongs.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2989e41f4b71Sopenharmony_ci| HUKS_TAG_NO_AUTH_REQUIRED                                   | HuksTagType.HUKS_TAG_TYPE_BOOL \| 303    | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
2990e41f4b71Sopenharmony_ci| HUKS_TAG_USER_AUTH_TYPE                                     | HuksTagType.HUKS_TAG_TYPE_UINT \| 304    | User authentication type. For details, see [HuksUserAuthType](#huksuserauthtype9). This parameter must be set together with [HuksAuthAccessType](#huksauthaccesstype9). You can set a maximum of two user authentication types at a time. For example, if **HuksAuthAccessType** is **HUKS_SECURE_ACCESS_INVALID_NEW_BIO_ENROLL**, you can set the user authentication type to **HUKS_USER_AUTH_TYPE_FACE**, **HUKS_USER_AUTH_TYPE_FINGERPRINT**, or| both.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2991e41f4b71Sopenharmony_ci| HUKS_TAG_AUTH_TIMEOUT                                       | HuksTagType.HUKS_TAG_TYPE_UINT \| 305    | One-time validity period of the authentication token.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2992e41f4b71Sopenharmony_ci| HUKS_TAG_AUTH_TOKEN                                         | HuksTagType.HUKS_TAG_TYPE_BYTES \| 306   | Authentication token.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2993e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_AUTH_ACCESS_TYPE<sup>9+</sup>                  | HuksTagType.HUKS_TAG_TYPE_UINT \| 307    | Access control type. For details, see [HuksAuthAccessType](#huksauthaccesstype9). This parameter must be set together with [HuksUserAuthType](#huksuserauthtype9).<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2994e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_SECURE_SIGN_TYPE<sup>9+</sup>                  | HuksTagType.HUKS_TAG_TYPE_UINT \| 308    | Signature type of the key generated or imported.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2995e41f4b71Sopenharmony_ci| HUKS_TAG_CHALLENGE_TYPE<sup>9+</sup>                        | HuksTagType.HUKS_TAG_TYPE_UINT \| 309    | Type of the challenge generated for a key. For details, see [HuksChallengeType](#hukschallengetype9).<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2996e41f4b71Sopenharmony_ci| HUKS_TAG_CHALLENGE_POS<sup>9+</sup>                         | HuksTagType.HUKS_TAG_TYPE_UINT \| 310    | Position of the 8-byte valid value in a custom challenge. For details, see [HuksChallengePosition](#hukschallengeposition9).<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2997e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_AUTH_PURPOSE<sup>10+</sup>                     | HuksTagType.HUKS_TAG_TYPE_UINT \|311     | Key authentication purpose.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2998e41f4b71Sopenharmony_ci| HUKS_TAG_AUTH_STORAGE_LEVEL<sup>11+</sup>                     | HuksTagType.HUKS_TAG_TYPE_UINT \|316    | Key storage security level, which is a value of [HuksAuthStorageLevel](#huksauthstoragelevel11).<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
2999e41f4b71Sopenharmony_ci| HUKS_TAG_USER_AUTH_MODE<sup>12+</sup>         | HuksTagType.HUKS_TAG_TYPE_UINT \| 319   | User authentication mode, which is a value of [HuksUserAuthMode](#huksuserauthmode12).<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3000e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_CHALLENGE                              | HuksTagType.HUKS_TAG_TYPE_BYTES \| 501   | Challenge value used in the attestation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3001e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_APPLICATION_ID                         | HuksTagType.HUKS_TAG_TYPE_BYTES \| 502   | Application ID used in the attestation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3002e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_BRAND<sup>(deprecated)</sup>        | HuksTagType.HUKS_TAG_TYPE_BYTES \| 503   | Brand of the device. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3003e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_DEVICE<sup>(deprecated)</sup>       | HuksTagType.HUKS_TAG_TYPE_BYTES \| 504   | ID of the device. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3004e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_PRODUCT<sup>(deprecated)</sup>      | HuksTagType.HUKS_TAG_TYPE_BYTES \| 505   | Product name of the device. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3005e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_SERIAL<sup>(deprecated)</sup>       | HuksTagType.HUKS_TAG_TYPE_BYTES \| 506   | SN of the device. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3006e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_IMEI<sup>(deprecated)</sup>         | HuksTagType.HUKS_TAG_TYPE_BYTES \| 507   | International mobile equipment identity (IMEI) of the device. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3007e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_MEID<sup>(deprecated)</sup>         | HuksTagType.HUKS_TAG_TYPE_BYTES \| 508   | Mobile equipment identity (MEID) of the device. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3008e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_MANUFACTURER<sup>(deprecated)</sup> | HuksTagType.HUKS_TAG_TYPE_BYTES \| 509   | Manufacturer of the device. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3009e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_MODEL<sup>(deprecated)</sup>        | HuksTagType.HUKS_TAG_TYPE_BYTES \| 510   | Device model. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3010e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_ALIAS                               | HuksTagType.HUKS_TAG_TYPE_BYTES \| 511   | Key alias used in the attestation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3011e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_SOCID<sup>(deprecated)</sup>        | HuksTagType.HUKS_TAG_TYPE_BYTES \| 512   | System-on-a-chip (SoCID) of the device. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3012e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_UDID<sup>(deprecated)</sup>         | HuksTagType.HUKS_TAG_TYPE_BYTES \| 513   | Unique device identifier (UDID) of the device. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3013e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO                      | HuksTagType.HUKS_TAG_TYPE_BYTES \| 514   | Security level used in the attestation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3014e41f4b71Sopenharmony_ci| HUKS_TAG_ATTESTATION_ID_VERSION_INFO                        | HuksTagType.HUKS_TAG_TYPE_BYTES \| 515   | Version information used in the attestation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3015e41f4b71Sopenharmony_ci| HUKS_TAG_IS_KEY_ALIAS                                       | HuksTagType.HUKS_TAG_TYPE_BOOL \| 1001   | Whether to use the alias passed in during key generation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
3016e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_STORAGE_FLAG                                   | HuksTagType.HUKS_TAG_TYPE_UINT \| 1002   | Key storage mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
3017e41f4b71Sopenharmony_ci| HUKS_TAG_IS_ALLOWED_WRAP                                    | HuksTagType.HUKS_TAG_TYPE_BOOL \| 1003   | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
3018e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_WRAP_TYPE                                      | HuksTagType.HUKS_TAG_TYPE_UINT \| 1004   | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
3019e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_AUTH_ID                                        | HuksTagType.HUKS_TAG_TYPE_BYTES \| 1005  | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3020e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_ROLE                                           | HuksTagType.HUKS_TAG_TYPE_UINT \| 1006   | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
3021e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_FLAG                                           | HuksTagType.HUKS_TAG_TYPE_UINT \| 1007   | Flag of the key.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
3022e41f4b71Sopenharmony_ci| HUKS_TAG_IS_ASYNCHRONIZED                                   | HuksTagType.HUKS_TAG_TYPE_UINT \| 1008   | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
3023e41f4b71Sopenharmony_ci| HUKS_TAG_SECURE_KEY_ALIAS<sup>(deprecated)</sup>            | HuksTagType.HUKS_TAG_TYPE_BOOL \| 1009   | Reserved field, which is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Core|
3024e41f4b71Sopenharmony_ci| HUKS_TAG_SECURE_KEY_UUID<sup>(deprecated)</sup>             | HuksTagType.HUKS_TAG_TYPE_BYTES \| 1010  | Reserved field, which is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3025e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_DOMAIN                                         | HuksTagType.HUKS_TAG_TYPE_UINT \| 1011   | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
3026e41f4b71Sopenharmony_ci| HUKS_TAG_IS_DEVICE_PASSWORD_SET<sup>11+</sup>                | HuksTagType.HUKS_TAG_TYPE_BOOL \| 1012   | Whether the key is accessible only when the user sets a lock screen password.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3027e41f4b71Sopenharmony_ci| HUKS_TAG_PROCESS_NAME<sup>(deprecated)</sup>                | HuksTagType.HUKS_TAG_TYPE_BYTES \| 10001 | Process name. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Core|
3028e41f4b71Sopenharmony_ci| HUKS_TAG_PACKAGE_NAME<sup>(deprecated)</sup>                | HuksTagType.HUKS_TAG_TYPE_BYTES \| 10002 | Reserved field, which is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3029e41f4b71Sopenharmony_ci| HUKS_TAG_ACCESS_TIME<sup>(deprecated)</sup>                 | HuksTagType.HUKS_TAG_TYPE_UINT \| 10003  | Reserved field, which is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3030e41f4b71Sopenharmony_ci| HUKS_TAG_USES_TIME<sup>(deprecated)</sup>                   | HuksTagType.HUKS_TAG_TYPE_UINT \| 10004  | Reserved field, which is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3031e41f4b71Sopenharmony_ci| HUKS_TAG_CRYPTO_CTX<sup>(deprecated)</sup>                  | HuksTagType.HUKS_TAG_TYPE_ULONG \| 10005 | Reserved field, which is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3032e41f4b71Sopenharmony_ci| HUKS_TAG_KEY                                                | HuksTagType.HUKS_TAG_TYPE_BYTES \| 10006 | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
3033e41f4b71Sopenharmony_ci| HUKS_TAG_KEY_VERSION<sup>(deprecated)</sup>                 | HuksTagType.HUKS_TAG_TYPE_UINT \| 10007  | Key version. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3034e41f4b71Sopenharmony_ci| HUKS_TAG_PAYLOAD_LEN<sup>(deprecated)</sup>                 | HuksTagType.HUKS_TAG_TYPE_UINT \| 10008  | Reserved field, which is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Extension|
3035e41f4b71Sopenharmony_ci| HUKS_TAG_AE_TAG                                             | HuksTagType.HUKS_TAG_TYPE_BYTES \| 10009 | Used to pass in the AEAD in GCM mode.<br>**Atomic service API**: This API can be used in atomic services since API version 11.<br> **System capability**: SystemCapability.Security.Huks.Core|
3036e41f4b71Sopenharmony_ci| HUKS_TAG_IS_KEY_HANDLE<sup>(deprecated)</sup>               | HuksTagType.HUKS_TAG_TYPE_ULONG \| 10010 | Reserved field, which is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Core|
3037e41f4b71Sopenharmony_ci| HUKS_TAG_OS_VERSION<sup>(deprecated)</sup>                  | HuksTagType.HUKS_TAG_TYPE_UINT \| 10101  | OS version. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Core|
3038e41f4b71Sopenharmony_ci| HUKS_TAG_OS_PATCHLEVEL<sup>(deprecated)</sup>               | HuksTagType.HUKS_TAG_TYPE_UINT \| 10102  | OS patch level. It is deprecated since API version 9.<br> **System capability**: SystemCapability.Security.Huks.Core|
3039e41f4b71Sopenharmony_ci| HUKS_TAG_SYMMETRIC_KEY_DATA                                 | HuksTagType.HUKS_TAG_TYPE_BYTES \| 20001 | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core|
3040e41f4b71Sopenharmony_ci| HUKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA                         | HuksTagType.HUKS_TAG_TYPE_BYTES \| 20002 | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
3041e41f4b71Sopenharmony_ci| HUKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA                        | HuksTagType.HUKS_TAG_TYPE_BYTES \| 20003 | Reserved.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br> **System capability**: SystemCapability.Security.Huks.Core<sup>12+</sup><br>SystemCapability.Security.Huks.Extension<sup>8-11</sup>|
3042e41f4b71Sopenharmony_ci
3043e41f4b71Sopenharmony_ci## huks.getSdkVersion<sup>(deprecated)</sup>
3044e41f4b71Sopenharmony_ci
3045e41f4b71Sopenharmony_cigetSdkVersion(options: HuksOptions) : string
3046e41f4b71Sopenharmony_ci
3047e41f4b71Sopenharmony_ciObtains the SDK version of the current system.
3048e41f4b71Sopenharmony_ci
3049e41f4b71Sopenharmony_ci> **NOTE**
3050e41f4b71Sopenharmony_ci>
3051e41f4b71Sopenharmony_ci> This API is deprecated since API version 11.
3052e41f4b71Sopenharmony_ci
3053e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3054e41f4b71Sopenharmony_ci
3055e41f4b71Sopenharmony_ci**Parameters**
3056e41f4b71Sopenharmony_ci
3057e41f4b71Sopenharmony_ci| Name | Type      | Mandatory| Description                     |
3058e41f4b71Sopenharmony_ci| ------- | ---------- | ---- | ------------------------- |
3059e41f4b71Sopenharmony_ci| options | [HuksOptions](#huksoptions) | Yes  | Empty object, which is used to hold the SDK version.|
3060e41f4b71Sopenharmony_ci
3061e41f4b71Sopenharmony_ci**Return value**
3062e41f4b71Sopenharmony_ci
3063e41f4b71Sopenharmony_ci| Type  | Description         |
3064e41f4b71Sopenharmony_ci| ------ | ------------- |
3065e41f4b71Sopenharmony_ci| string | SDK version obtained.|
3066e41f4b71Sopenharmony_ci
3067e41f4b71Sopenharmony_ci**Example**
3068e41f4b71Sopenharmony_ci
3069e41f4b71Sopenharmony_ci```ts
3070e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3071e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
3072e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
3073e41f4b71Sopenharmony_ci    properties: []
3074e41f4b71Sopenharmony_ci};
3075e41f4b71Sopenharmony_cilet result = huks.getSdkVersion(emptyOptions);
3076e41f4b71Sopenharmony_ci```
3077e41f4b71Sopenharmony_ci
3078e41f4b71Sopenharmony_ci## huks.generateKey<sup>(deprecated)</sup>
3079e41f4b71Sopenharmony_ci
3080e41f4b71Sopenharmony_cigenerateKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
3081e41f4b71Sopenharmony_ci
3082e41f4b71Sopenharmony_ciGenerates a key. This API uses an asynchronous callback to return the result.
3083e41f4b71Sopenharmony_ci
3084e41f4b71Sopenharmony_ci> **NOTE**
3085e41f4b71Sopenharmony_ci>
3086e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.generateKeyItem<sup>9+</sup>](#huksgeneratekeyitem9).
3087e41f4b71Sopenharmony_ci
3088e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3089e41f4b71Sopenharmony_ci
3090e41f4b71Sopenharmony_ci**Parameters**
3091e41f4b71Sopenharmony_ci
3092e41f4b71Sopenharmony_ci| Name  | Type                                     | Mandatory| Description                                                        |
3093e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
3094e41f4b71Sopenharmony_ci| keyAlias | string                                    | Yes  | Alias of the key.                                                       |
3095e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)               | Yes  | Tags required for generating the key.                                    |
3096e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksResult](#huksresultdeprecated)> | Yes  | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** is returned. If the operation fails, an error code defined in **HuksResult** is returned.|
3097e41f4b71Sopenharmony_ci
3098e41f4b71Sopenharmony_ci**Example**
3099e41f4b71Sopenharmony_ci
3100e41f4b71Sopenharmony_ci```ts
3101e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3102e41f4b71Sopenharmony_ci/* Generate an RSA key of 512 bits. */
3103e41f4b71Sopenharmony_ci
3104e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3105e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = [
3106e41f4b71Sopenharmony_ci    {
3107e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
3108e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_RSA
3109e41f4b71Sopenharmony_ci    },
3110e41f4b71Sopenharmony_ci    {
3111e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
3112e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_512
3113e41f4b71Sopenharmony_ci    },
3114e41f4b71Sopenharmony_ci    {
3115e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
3116e41f4b71Sopenharmony_ci        value:
3117e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT |
3118e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT
3119e41f4b71Sopenharmony_ci    },
3120e41f4b71Sopenharmony_ci    {
3121e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PADDING,
3122e41f4b71Sopenharmony_ci        value: huks.HuksKeyPadding.HUKS_PADDING_OAEP
3123e41f4b71Sopenharmony_ci    },
3124e41f4b71Sopenharmony_ci    {
3125e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_DIGEST,
3126e41f4b71Sopenharmony_ci        value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
3127e41f4b71Sopenharmony_ci    }
3128e41f4b71Sopenharmony_ci];
3129e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
3130e41f4b71Sopenharmony_ci    properties: properties
3131e41f4b71Sopenharmony_ci};
3132e41f4b71Sopenharmony_cihuks.generateKey(keyAlias, options, (err, data) => {
3133e41f4b71Sopenharmony_ci});
3134e41f4b71Sopenharmony_ci```
3135e41f4b71Sopenharmony_ci
3136e41f4b71Sopenharmony_ci## huks.generateKey<sup>(deprecated)</sup>
3137e41f4b71Sopenharmony_ci
3138e41f4b71Sopenharmony_cigenerateKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
3139e41f4b71Sopenharmony_ci
3140e41f4b71Sopenharmony_ciGenerates a key. This API uses a promise to return the result.
3141e41f4b71Sopenharmony_ci
3142e41f4b71Sopenharmony_ci> **NOTE**
3143e41f4b71Sopenharmony_ci>
3144e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.generateKeyItem<sup>9+</sup>](#huksgeneratekeyitem9-1).
3145e41f4b71Sopenharmony_ci
3146e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3147e41f4b71Sopenharmony_ci
3148e41f4b71Sopenharmony_ci**Parameters**
3149e41f4b71Sopenharmony_ci
3150e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                    |
3151e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ------------------------ |
3152e41f4b71Sopenharmony_ci| keyAlias | string                      | Yes  | Alias of the key.              |
3153e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Tags required for generating the key.|
3154e41f4b71Sopenharmony_ci
3155e41f4b71Sopenharmony_ci**Return value**
3156e41f4b71Sopenharmony_ci
3157e41f4b71Sopenharmony_ci| Type                               | Description                                              |
3158e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
3159e41f4b71Sopenharmony_ci| Promise\<[HuksResult](#huksresultdeprecated)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** is returned. If the operation fails, an error code is returned.|
3160e41f4b71Sopenharmony_ci
3161e41f4b71Sopenharmony_ci**Example**
3162e41f4b71Sopenharmony_ci
3163e41f4b71Sopenharmony_ci```ts
3164e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3165e41f4b71Sopenharmony_ci/* Generate a 256-bit ECC key. */
3166e41f4b71Sopenharmony_ci
3167e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3168e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = [
3169e41f4b71Sopenharmony_ci    {
3170e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
3171e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_ECC
3172e41f4b71Sopenharmony_ci    },
3173e41f4b71Sopenharmony_ci    {
3174e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
3175e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_ECC_KEY_SIZE_256
3176e41f4b71Sopenharmony_ci    },
3177e41f4b71Sopenharmony_ci    {
3178e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
3179e41f4b71Sopenharmony_ci        value:
3180e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN |
3181e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY
3182e41f4b71Sopenharmony_ci    },
3183e41f4b71Sopenharmony_ci    {
3184e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_DIGEST,
3185e41f4b71Sopenharmony_ci        value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
3186e41f4b71Sopenharmony_ci    }
3187e41f4b71Sopenharmony_ci];
3188e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
3189e41f4b71Sopenharmony_ci    properties: properties
3190e41f4b71Sopenharmony_ci};
3191e41f4b71Sopenharmony_cilet result = huks.generateKey(keyAlias, options);
3192e41f4b71Sopenharmony_ci```
3193e41f4b71Sopenharmony_ci
3194e41f4b71Sopenharmony_ci## huks.deleteKey<sup>(deprecated)</sup>
3195e41f4b71Sopenharmony_ci
3196e41f4b71Sopenharmony_cideleteKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
3197e41f4b71Sopenharmony_ci
3198e41f4b71Sopenharmony_ciDeletes a key. This API uses an asynchronous callback to return the result.
3199e41f4b71Sopenharmony_ci
3200e41f4b71Sopenharmony_ci> **NOTE**
3201e41f4b71Sopenharmony_ci>
3202e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.deleteKeyItem<sup>9+</sup>](#huksdeletekeyitem9).
3203e41f4b71Sopenharmony_ci
3204e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3205e41f4b71Sopenharmony_ci
3206e41f4b71Sopenharmony_ci**Parameters**
3207e41f4b71Sopenharmony_ci
3208e41f4b71Sopenharmony_ci| Name  | Type                                     | Mandatory| Description                                                |
3209e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- |----------------------------------------------------|
3210e41f4b71Sopenharmony_ci| keyAlias | string                                    | Yes  | Alias of the key to delete. It must be the key alias passed in when the key was generated.                               |
3211e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)               | Yes  | Options for deleting the key.|
3212e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksResult](#huksresultdeprecated)> | Yes  | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** is returned. If the operation fails, an error code is returned.              |
3213e41f4b71Sopenharmony_ci
3214e41f4b71Sopenharmony_ci**Example**
3215e41f4b71Sopenharmony_ci
3216e41f4b71Sopenharmony_ci```ts
3217e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3218e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
3219e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3220e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
3221e41f4b71Sopenharmony_ci    properties: []
3222e41f4b71Sopenharmony_ci};
3223e41f4b71Sopenharmony_cihuks.deleteKey(keyAlias, emptyOptions, (err, data) => {
3224e41f4b71Sopenharmony_ci});
3225e41f4b71Sopenharmony_ci```
3226e41f4b71Sopenharmony_ci
3227e41f4b71Sopenharmony_ci## huks.deleteKey<sup>(deprecated)</sup>
3228e41f4b71Sopenharmony_ci
3229e41f4b71Sopenharmony_cideleteKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
3230e41f4b71Sopenharmony_ci
3231e41f4b71Sopenharmony_ciDeletes a key. This API uses a promise to return the result.
3232e41f4b71Sopenharmony_ci
3233e41f4b71Sopenharmony_ci> **NOTE**
3234e41f4b71Sopenharmony_ci>
3235e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.deleteKeyItem<sup>9+</sup>](#huksdeletekeyitem9-1).
3236e41f4b71Sopenharmony_ci
3237e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3238e41f4b71Sopenharmony_ci
3239e41f4b71Sopenharmony_ci**Parameters**
3240e41f4b71Sopenharmony_ci
3241e41f4b71Sopenharmony_ci| Name  | Type       | Mandatory| Description                                                 |
3242e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | ----------------------------------------------------- |
3243e41f4b71Sopenharmony_ci| keyAlias | string      | Yes  | Alias of the key to delete. It must be the key alias passed in when the key was generated.|
3244e41f4b71Sopenharmony_ci| options | [HuksOptions](#huksoptions) | Yes  | Options for deleting the key.|
3245e41f4b71Sopenharmony_ci
3246e41f4b71Sopenharmony_ci**Return value**
3247e41f4b71Sopenharmony_ci
3248e41f4b71Sopenharmony_ci| Type                               | Description                                              |
3249e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
3250e41f4b71Sopenharmony_ci| Promise\<[HuksResult](#huksresultdeprecated)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** is returned. If the operation fails, an error code is returned.|
3251e41f4b71Sopenharmony_ci
3252e41f4b71Sopenharmony_ci**Example**
3253e41f4b71Sopenharmony_ci
3254e41f4b71Sopenharmony_ci```ts
3255e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3256e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
3257e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3258e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
3259e41f4b71Sopenharmony_ci    properties: []
3260e41f4b71Sopenharmony_ci};
3261e41f4b71Sopenharmony_cilet result = huks.deleteKey(keyAlias, emptyOptions);
3262e41f4b71Sopenharmony_ci```
3263e41f4b71Sopenharmony_ci
3264e41f4b71Sopenharmony_ci## huks.importKey<sup>(deprecated)</sup>
3265e41f4b71Sopenharmony_ci
3266e41f4b71Sopenharmony_ciimportKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
3267e41f4b71Sopenharmony_ci
3268e41f4b71Sopenharmony_ciImports a key in plaintext. This API uses an asynchronous callback to return the result.
3269e41f4b71Sopenharmony_ci
3270e41f4b71Sopenharmony_ci> **NOTE**
3271e41f4b71Sopenharmony_ci>
3272e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.importKeyItem<sup>9+</sup>](#huksimportkeyitem9).
3273e41f4b71Sopenharmony_ci
3274e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3275e41f4b71Sopenharmony_ci
3276e41f4b71Sopenharmony_ci**Parameters**
3277e41f4b71Sopenharmony_ci
3278e41f4b71Sopenharmony_ci| Name  | Type                    | Mandatory| Description                                             |
3279e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- | ------------------------------------------------- |
3280e41f4b71Sopenharmony_ci| keyAlias | string                   | Yes  | Alias of the key.|
3281e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Tags required for the import and key to import.|
3282e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksResult](#huksresultdeprecated)> | Yes  | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** is returned. If the operation fails, an error code is returned.|
3283e41f4b71Sopenharmony_ci
3284e41f4b71Sopenharmony_ci**Example**
3285e41f4b71Sopenharmony_ci
3286e41f4b71Sopenharmony_ci```ts
3287e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3288e41f4b71Sopenharmony_ci/* Import a 256-bit AES key. */
3289e41f4b71Sopenharmony_ci
3290e41f4b71Sopenharmony_cilet plainTextSize32 = makeRandomArr(32);
3291e41f4b71Sopenharmony_cifunction makeRandomArr(size: number) {
3292e41f4b71Sopenharmony_ci    let arr = new Uint8Array(size);
3293e41f4b71Sopenharmony_ci    for (let i = 0; i < size; i++) {
3294e41f4b71Sopenharmony_ci        arr[i] = Math.floor(Math.random() * 10);
3295e41f4b71Sopenharmony_ci    }
3296e41f4b71Sopenharmony_ci    return arr;
3297e41f4b71Sopenharmony_ci};
3298e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3299e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = [
3300e41f4b71Sopenharmony_ci    {
3301e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
3302e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_AES
3303e41f4b71Sopenharmony_ci    },
3304e41f4b71Sopenharmony_ci    {
3305e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
3306e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256
3307e41f4b71Sopenharmony_ci    },
3308e41f4b71Sopenharmony_ci    {
3309e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
3310e41f4b71Sopenharmony_ci        value:
3311e41f4b71Sopenharmony_ci        huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT
3312e41f4b71Sopenharmony_ci    },
3313e41f4b71Sopenharmony_ci    {
3314e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PADDING,
3315e41f4b71Sopenharmony_ci        value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7
3316e41f4b71Sopenharmony_ci    },
3317e41f4b71Sopenharmony_ci    {
3318e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
3319e41f4b71Sopenharmony_ci        value: huks.HuksCipherMode.HUKS_MODE_ECB
3320e41f4b71Sopenharmony_ci    }
3321e41f4b71Sopenharmony_ci];
3322e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
3323e41f4b71Sopenharmony_ci    properties: properties,
3324e41f4b71Sopenharmony_ci    inData: plainTextSize32
3325e41f4b71Sopenharmony_ci};
3326e41f4b71Sopenharmony_cihuks.importKey(keyAlias, options, (err, data) => {
3327e41f4b71Sopenharmony_ci});
3328e41f4b71Sopenharmony_ci```
3329e41f4b71Sopenharmony_ci
3330e41f4b71Sopenharmony_ci## huks.importKey<sup>(deprecated)</sup>
3331e41f4b71Sopenharmony_ci
3332e41f4b71Sopenharmony_ciimportKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
3333e41f4b71Sopenharmony_ci
3334e41f4b71Sopenharmony_ciImports a key in plaintext. This API uses a promise to return the result.
3335e41f4b71Sopenharmony_ci
3336e41f4b71Sopenharmony_ci> **NOTE**
3337e41f4b71Sopenharmony_ci>
3338e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.importKeyItem<sup>9+</sup>](#huksimportkeyitem9-1).
3339e41f4b71Sopenharmony_ci
3340e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3341e41f4b71Sopenharmony_ci
3342e41f4b71Sopenharmony_ci**Parameters**
3343e41f4b71Sopenharmony_ci
3344e41f4b71Sopenharmony_ci| Name  | Type       | Mandatory| Description                                |
3345e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | ------------------------------------ |
3346e41f4b71Sopenharmony_ci| keyAlias | string      | Yes  | Alias of the key.|
3347e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Tags required for the import and key to import.|
3348e41f4b71Sopenharmony_ci
3349e41f4b71Sopenharmony_ci**Return value**
3350e41f4b71Sopenharmony_ci
3351e41f4b71Sopenharmony_ci| Type                               | Description                                              |
3352e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
3353e41f4b71Sopenharmony_ci| Promise\<[HuksResult](#huksresultdeprecated)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** is returned. If the operation fails, an error code is returned.|
3354e41f4b71Sopenharmony_ci
3355e41f4b71Sopenharmony_ci**Example**
3356e41f4b71Sopenharmony_ci
3357e41f4b71Sopenharmony_ci```ts
3358e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3359e41f4b71Sopenharmony_ci/* Import an AES key of 128 bits. */
3360e41f4b71Sopenharmony_ci
3361e41f4b71Sopenharmony_cilet plainTextSize32 = makeRandomArr(32);
3362e41f4b71Sopenharmony_cifunction makeRandomArr(size: number) {
3363e41f4b71Sopenharmony_ci    let arr = new Uint8Array(size);
3364e41f4b71Sopenharmony_ci    for (let i = 0; i < size; i++) {
3365e41f4b71Sopenharmony_ci        arr[i] = Math.floor(Math.random() * 10);
3366e41f4b71Sopenharmony_ci    }
3367e41f4b71Sopenharmony_ci    return arr;
3368e41f4b71Sopenharmony_ci};
3369e41f4b71Sopenharmony_ci/* Step 1 Generate a key. */
3370e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3371e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = [
3372e41f4b71Sopenharmony_ci    {
3373e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
3374e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_AES
3375e41f4b71Sopenharmony_ci    },
3376e41f4b71Sopenharmony_ci    {
3377e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
3378e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128
3379e41f4b71Sopenharmony_ci    },
3380e41f4b71Sopenharmony_ci    {
3381e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
3382e41f4b71Sopenharmony_ci        value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT
3383e41f4b71Sopenharmony_ci    },
3384e41f4b71Sopenharmony_ci    {
3385e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PADDING,
3386e41f4b71Sopenharmony_ci        value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7
3387e41f4b71Sopenharmony_ci    },
3388e41f4b71Sopenharmony_ci    {
3389e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
3390e41f4b71Sopenharmony_ci        value: huks.HuksCipherMode.HUKS_MODE_ECB
3391e41f4b71Sopenharmony_ci    }
3392e41f4b71Sopenharmony_ci];
3393e41f4b71Sopenharmony_cilet huksOptions: huks.HuksOptions = {
3394e41f4b71Sopenharmony_ci    properties: properties,
3395e41f4b71Sopenharmony_ci    inData: plainTextSize32
3396e41f4b71Sopenharmony_ci};
3397e41f4b71Sopenharmony_cilet result = huks.importKey(keyAlias, huksOptions);
3398e41f4b71Sopenharmony_ci```
3399e41f4b71Sopenharmony_ci
3400e41f4b71Sopenharmony_ci## huks.exportKey<sup>(deprecated)</sup>
3401e41f4b71Sopenharmony_ci
3402e41f4b71Sopenharmony_ciexportKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
3403e41f4b71Sopenharmony_ci
3404e41f4b71Sopenharmony_ciExports a key. This API uses an asynchronous callback to return the result.
3405e41f4b71Sopenharmony_ci
3406e41f4b71Sopenharmony_ci> **NOTE**
3407e41f4b71Sopenharmony_ci>
3408e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.exportKeyItem<sup>9+</sup>](#huksexportkeyitem9).
3409e41f4b71Sopenharmony_ci
3410e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3411e41f4b71Sopenharmony_ci
3412e41f4b71Sopenharmony_ci**Parameters**
3413e41f4b71Sopenharmony_ci
3414e41f4b71Sopenharmony_ci| Name  | Type                                     | Mandatory| Description                                                        |
3415e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
3416e41f4b71Sopenharmony_ci| keyAlias | string                                    | Yes  | Key alias, which must be the same as the alias used when the key was generated.                |
3417e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)               | Yes  | Empty object (leave this parameter empty).                                    |
3418e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksResult](#huksresultdeprecated)> | Yes  | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** is returned and **outData** contains the public key exported. If the operation fails, an error code is returned.|
3419e41f4b71Sopenharmony_ci
3420e41f4b71Sopenharmony_ci**Example**
3421e41f4b71Sopenharmony_ci
3422e41f4b71Sopenharmony_ci```ts
3423e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3424e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
3425e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3426e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
3427e41f4b71Sopenharmony_ci    properties: []
3428e41f4b71Sopenharmony_ci};
3429e41f4b71Sopenharmony_cihuks.exportKey(keyAlias, emptyOptions, (err, data) => {
3430e41f4b71Sopenharmony_ci});
3431e41f4b71Sopenharmony_ci```
3432e41f4b71Sopenharmony_ci
3433e41f4b71Sopenharmony_ci## huks.exportKey<sup>(deprecated)</sup>
3434e41f4b71Sopenharmony_ci
3435e41f4b71Sopenharmony_ciexportKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
3436e41f4b71Sopenharmony_ci
3437e41f4b71Sopenharmony_ciExports a key. This API uses a promise to return the result.
3438e41f4b71Sopenharmony_ci
3439e41f4b71Sopenharmony_ci> **NOTE**
3440e41f4b71Sopenharmony_ci>
3441e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.exportKeyItem<sup>9+</sup>](#huksexportkeyitem9-1).
3442e41f4b71Sopenharmony_ci
3443e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3444e41f4b71Sopenharmony_ci
3445e41f4b71Sopenharmony_ci**Parameters**
3446e41f4b71Sopenharmony_ci
3447e41f4b71Sopenharmony_ci| Name  | Type       | Mandatory| Description                                                        |
3448e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | ------------------------------------------------------------ |
3449e41f4b71Sopenharmony_ci| keyAlias | string      | Yes  | Key alias, which must be the same as the alias used when the key was generated.|
3450e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Empty object (leave this parameter empty).|
3451e41f4b71Sopenharmony_ci
3452e41f4b71Sopenharmony_ci**Return value**
3453e41f4b71Sopenharmony_ci
3454e41f4b71Sopenharmony_ci| Type                               | Description                                                        |
3455e41f4b71Sopenharmony_ci| ----------------------------------- | ------------------------------------------------------------ |
3456e41f4b71Sopenharmony_ci| Promise\<[HuksResult](#huksresultdeprecated)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** is returned and **outData** contains the public key exported. If the operation fails, an error code is returned.|
3457e41f4b71Sopenharmony_ci
3458e41f4b71Sopenharmony_ci**Example**
3459e41f4b71Sopenharmony_ci
3460e41f4b71Sopenharmony_ci```ts
3461e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3462e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
3463e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3464e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
3465e41f4b71Sopenharmony_ci    properties: []
3466e41f4b71Sopenharmony_ci};
3467e41f4b71Sopenharmony_cilet result = huks.exportKey(keyAlias, emptyOptions);
3468e41f4b71Sopenharmony_ci```
3469e41f4b71Sopenharmony_ci
3470e41f4b71Sopenharmony_ci## huks.getKeyProperties<sup>(deprecated)</sup>
3471e41f4b71Sopenharmony_ci
3472e41f4b71Sopenharmony_cigetKeyProperties(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
3473e41f4b71Sopenharmony_ci
3474e41f4b71Sopenharmony_ciObtains key properties. This API uses an asynchronous callback to return the result.
3475e41f4b71Sopenharmony_ci
3476e41f4b71Sopenharmony_ci> **NOTE**
3477e41f4b71Sopenharmony_ci>
3478e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.getKeyItemProperties<sup>9+</sup>](#huksgetkeyitemproperties9).
3479e41f4b71Sopenharmony_ci
3480e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3481e41f4b71Sopenharmony_ci
3482e41f4b71Sopenharmony_ci**Parameters**
3483e41f4b71Sopenharmony_ci
3484e41f4b71Sopenharmony_ci| Name  | Type                                     | Mandatory| Description                                                        |
3485e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
3486e41f4b71Sopenharmony_ci| keyAlias | string                                    | Yes  | Key alias, which must be the same as the alias used when the key was generated.                |
3487e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)               | Yes  | Empty object (leave this parameter empty).                                    |
3488e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksResult](#huksresultdeprecated)> | Yes  | Callback used to return the result. If the operation is successful, **errorCode** is **HUKS_SUCCESS**; otherwise, an error code is returned.|
3489e41f4b71Sopenharmony_ci
3490e41f4b71Sopenharmony_ci**Example**
3491e41f4b71Sopenharmony_ci
3492e41f4b71Sopenharmony_ci```ts
3493e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3494e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
3495e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3496e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
3497e41f4b71Sopenharmony_ci    properties: []
3498e41f4b71Sopenharmony_ci};
3499e41f4b71Sopenharmony_cihuks.getKeyProperties(keyAlias, emptyOptions, (err, data) => {
3500e41f4b71Sopenharmony_ci});
3501e41f4b71Sopenharmony_ci```
3502e41f4b71Sopenharmony_ci
3503e41f4b71Sopenharmony_ci## huks.getKeyProperties<sup>(deprecated)</sup>
3504e41f4b71Sopenharmony_ci
3505e41f4b71Sopenharmony_cigetKeyProperties(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
3506e41f4b71Sopenharmony_ci
3507e41f4b71Sopenharmony_ciObtains key properties. This API uses a promise to return the result.
3508e41f4b71Sopenharmony_ci
3509e41f4b71Sopenharmony_ci> **NOTE**
3510e41f4b71Sopenharmony_ci>
3511e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.getKeyItemProperties<sup>9+</sup>](#huksgetkeyitemproperties9-1).
3512e41f4b71Sopenharmony_ci
3513e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3514e41f4b71Sopenharmony_ci
3515e41f4b71Sopenharmony_ci**Parameters**
3516e41f4b71Sopenharmony_ci
3517e41f4b71Sopenharmony_ci| Name  | Type       | Mandatory| Description                                                        |
3518e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | ------------------------------------------------------------ |
3519e41f4b71Sopenharmony_ci| keyAlias | string      | Yes  | Key alias, which must be the same as the alias used when the key was generated.|
3520e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Empty object (leave this parameter empty).|
3521e41f4b71Sopenharmony_ci
3522e41f4b71Sopenharmony_ci**Return value**
3523e41f4b71Sopenharmony_ci
3524e41f4b71Sopenharmony_ci| Type              | Description                                                        |
3525e41f4b71Sopenharmony_ci| ------------------ | ------------------------------------------------------------ |
3526e41f4b71Sopenharmony_ci| Promise\<[HuksResult](#huksoptions)> | Promise used to return the result. If the operation is successful, **errorCode** is **HUKS_SUCCESS** and **properties** returns the parameters required for generating the key. If the operation fails, an error code is returned.|
3527e41f4b71Sopenharmony_ci
3528e41f4b71Sopenharmony_ci**Example**
3529e41f4b71Sopenharmony_ci
3530e41f4b71Sopenharmony_ci```ts
3531e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3532e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
3533e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3534e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
3535e41f4b71Sopenharmony_ci    properties: []
3536e41f4b71Sopenharmony_ci};
3537e41f4b71Sopenharmony_cilet result = huks.getKeyProperties(keyAlias, emptyOptions);
3538e41f4b71Sopenharmony_ci```
3539e41f4b71Sopenharmony_ci
3540e41f4b71Sopenharmony_ci## huks.isKeyExist<sup>(deprecated)</sup>
3541e41f4b71Sopenharmony_ci
3542e41f4b71Sopenharmony_ciisKeyExist(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<boolean>) : void
3543e41f4b71Sopenharmony_ci
3544e41f4b71Sopenharmony_ciChecks whether a key exists. This API uses an asynchronous callback to return the result.
3545e41f4b71Sopenharmony_ci
3546e41f4b71Sopenharmony_ci> **NOTE**
3547e41f4b71Sopenharmony_ci>
3548e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.isKeyItemExist<sup>9+</sup>](#huksiskeyitemexist9).
3549e41f4b71Sopenharmony_ci
3550e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3551e41f4b71Sopenharmony_ci
3552e41f4b71Sopenharmony_ci**Parameters**
3553e41f4b71Sopenharmony_ci
3554e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                 |
3555e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------- |
3556e41f4b71Sopenharmony_ci| keyAlias | string                 | Yes  | Alias of the key to check.|
3557e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Options for checking the key.|
3558e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean> | Yes  | Callback used to return the result. The value **true** means the key exists; the value **false** means the opposite.|
3559e41f4b71Sopenharmony_ci
3560e41f4b71Sopenharmony_ci**Example**
3561e41f4b71Sopenharmony_ci
3562e41f4b71Sopenharmony_ci```ts
3563e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3564e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
3565e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3566e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
3567e41f4b71Sopenharmony_ci    properties: []
3568e41f4b71Sopenharmony_ci};
3569e41f4b71Sopenharmony_cihuks.isKeyExist(keyAlias, emptyOptions, (err, data) => {
3570e41f4b71Sopenharmony_ci});
3571e41f4b71Sopenharmony_ci```
3572e41f4b71Sopenharmony_ci
3573e41f4b71Sopenharmony_ci## huks.isKeyExist<sup>(deprecated)</sup>
3574e41f4b71Sopenharmony_ci
3575e41f4b71Sopenharmony_ciisKeyExist(keyAlias: string, options: HuksOptions) : Promise\<boolean>
3576e41f4b71Sopenharmony_ci
3577e41f4b71Sopenharmony_ciChecks whether a key exists. This API uses a promise to return the result.
3578e41f4b71Sopenharmony_ci
3579e41f4b71Sopenharmony_ci> **NOTE**
3580e41f4b71Sopenharmony_ci>
3581e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.isKeyItemExist<sup>9+</sup>](#huksiskeyitemexist9-1).
3582e41f4b71Sopenharmony_ci
3583e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3584e41f4b71Sopenharmony_ci
3585e41f4b71Sopenharmony_ci**Parameters**
3586e41f4b71Sopenharmony_ci
3587e41f4b71Sopenharmony_ci| Name  | Type       | Mandatory| Description                            |
3588e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | -------------------------------- |
3589e41f4b71Sopenharmony_ci| keyAlias | string      | Yes  | Alias of the key to check.|
3590e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Options for checking the key.|
3591e41f4b71Sopenharmony_ci
3592e41f4b71Sopenharmony_ci**Return value**
3593e41f4b71Sopenharmony_ci
3594e41f4b71Sopenharmony_ci| Type             | Description                                   |
3595e41f4b71Sopenharmony_ci| ----------------- | --------------------------------------- |
3596e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. The value **true** means the key exists; the value **false** means the opposite.|
3597e41f4b71Sopenharmony_ci
3598e41f4b71Sopenharmony_ci**Example**
3599e41f4b71Sopenharmony_ci
3600e41f4b71Sopenharmony_ci```ts
3601e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3602e41f4b71Sopenharmony_ci/* Set options to emptyOptions. */
3603e41f4b71Sopenharmony_cilet keyAlias = 'keyAlias';
3604e41f4b71Sopenharmony_cilet emptyOptions: huks.HuksOptions = {
3605e41f4b71Sopenharmony_ci    properties: []
3606e41f4b71Sopenharmony_ci};
3607e41f4b71Sopenharmony_cilet result = huks.isKeyExist(keyAlias, emptyOptions);
3608e41f4b71Sopenharmony_ci```
3609e41f4b71Sopenharmony_ci
3610e41f4b71Sopenharmony_ci## huks.init<sup>(deprecated)</sup>
3611e41f4b71Sopenharmony_ci
3612e41f4b71Sopenharmony_ciinit(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksHandle>) : void
3613e41f4b71Sopenharmony_ci
3614e41f4b71Sopenharmony_ciInitializes a session for a key operation. This API uses an asynchronous callback to return the result. **huks.init**, **huks.update**, and **huks.finish** must be used together.
3615e41f4b71Sopenharmony_ci
3616e41f4b71Sopenharmony_ci> **NOTE**
3617e41f4b71Sopenharmony_ci>
3618e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.initSession<sup>9+</sup>](#huksinitsession9-1).
3619e41f4b71Sopenharmony_ci
3620e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3621e41f4b71Sopenharmony_ci
3622e41f4b71Sopenharmony_ci**Parameters**
3623e41f4b71Sopenharmony_ci
3624e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                 |
3625e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------- |
3626e41f4b71Sopenharmony_ci| keyAlias | string                 | Yes  | Alias of the target key.|
3627e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Parameter set used for the **init** operation.|
3628e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksHandle](#hukshandledeprecated)> | Yes  | Callback used to return a session handle for subsequent operations.|
3629e41f4b71Sopenharmony_ci
3630e41f4b71Sopenharmony_ci## huks.init<sup>(deprecated)</sup>
3631e41f4b71Sopenharmony_ci
3632e41f4b71Sopenharmony_ciinit(keyAlias: string, options: HuksOptions) : Promise\<HuksHandle>
3633e41f4b71Sopenharmony_ci
3634e41f4b71Sopenharmony_ciInitializes a session for a key operation. This API uses a promise to return the result. **huks.init**, **huks.update**, and **huks.finish** must be used together.
3635e41f4b71Sopenharmony_ci
3636e41f4b71Sopenharmony_ci> **NOTE**
3637e41f4b71Sopenharmony_ci>
3638e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.initSession<sup>9+</sup>](#huksinitsession9-1).
3639e41f4b71Sopenharmony_ci
3640e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3641e41f4b71Sopenharmony_ci
3642e41f4b71Sopenharmony_ci**Parameters**
3643e41f4b71Sopenharmony_ci
3644e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                 |
3645e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------- |
3646e41f4b71Sopenharmony_ci| keyAlias | string                 | Yes  | Alias of the target key.|
3647e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Parameter set used for the **init** operation.|
3648e41f4b71Sopenharmony_ci
3649e41f4b71Sopenharmony_ci**Return value**
3650e41f4b71Sopenharmony_ci
3651e41f4b71Sopenharmony_ci| Type                               | Description                                              |
3652e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
3653e41f4b71Sopenharmony_ci| Promise\<[HuksHandle](#hukshandledeprecated)> | Promise used to return a session handle for subsequent operations.|
3654e41f4b71Sopenharmony_ci
3655e41f4b71Sopenharmony_ci## huks.update<sup>(deprecated)</sup>
3656e41f4b71Sopenharmony_ci
3657e41f4b71Sopenharmony_ciupdate(handle: number, token?: Uint8Array, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
3658e41f4b71Sopenharmony_ci
3659e41f4b71Sopenharmony_ciUpdates the key operation by segment. This API uses an asynchronous callback to return the result. **huks.init**, **huks.update**, and **huks.finish** must be used together.
3660e41f4b71Sopenharmony_ci
3661e41f4b71Sopenharmony_ci> **NOTE**
3662e41f4b71Sopenharmony_ci>
3663e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.updateSession<sup>9+</sup>](#huksupdatesession9-1).
3664e41f4b71Sopenharmony_ci
3665e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3666e41f4b71Sopenharmony_ci
3667e41f4b71Sopenharmony_ci**Parameters**
3668e41f4b71Sopenharmony_ci
3669e41f4b71Sopenharmony_ci| Name  | Type                                     | Mandatory| Description                                        |
3670e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | ---- | -------------------------------------------- |
3671e41f4b71Sopenharmony_ci| handle   | number                                    | Yes  | Handle for the **update** operation.                        |
3672e41f4b71Sopenharmony_ci| token    | Uint8Array                                | No  | Token of the **update** operation.                         |
3673e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions)               | Yes  | Parameter set used for the **update** operation.                      |
3674e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksResult](#huksresultdeprecated)> | Yes  | Callback used to return the **update** operation result.|
3675e41f4b71Sopenharmony_ci
3676e41f4b71Sopenharmony_ci## huks.update<sup>(deprecated)</sup>
3677e41f4b71Sopenharmony_ci
3678e41f4b71Sopenharmony_ciupdate(handle: number, token?: Uint8Array, options: HuksOptions) : Promise\<HuksResult>;
3679e41f4b71Sopenharmony_ci
3680e41f4b71Sopenharmony_ciUpdates the key operation by segment. This API uses a promise to return the result. **huks.init**, **huks.update**, and **huks.finish** must be used together.
3681e41f4b71Sopenharmony_ci
3682e41f4b71Sopenharmony_ci> **NOTE**
3683e41f4b71Sopenharmony_ci>
3684e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.updateSession<sup>9+</sup>](#huksupdatesession9-2).
3685e41f4b71Sopenharmony_ci
3686e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3687e41f4b71Sopenharmony_ci
3688e41f4b71Sopenharmony_ci**Parameters**
3689e41f4b71Sopenharmony_ci
3690e41f4b71Sopenharmony_ci| Name | Type                               | Mandatory| Description                                        |
3691e41f4b71Sopenharmony_ci| ------- | ----------------------------------- | ---- | -------------------------------------------- |
3692e41f4b71Sopenharmony_ci| handle  | number                              | Yes  | Handle for the **update** operation.                        |
3693e41f4b71Sopenharmony_ci| token   | Uint8Array                          | No  | Token of the **update** operation.                         |
3694e41f4b71Sopenharmony_ci| options | [HuksOptions](#huksoptions)         | Yes  | Parameter set used for the **update** operation.                      |
3695e41f4b71Sopenharmony_ci
3696e41f4b71Sopenharmony_ci**Return value**
3697e41f4b71Sopenharmony_ci
3698e41f4b71Sopenharmony_ci| Type                               | Description                                              |
3699e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
3700e41f4b71Sopenharmony_ci| Promise\<[HuksResult](#huksresultdeprecated)> | Promise used to return the **update** operation result.|
3701e41f4b71Sopenharmony_ci
3702e41f4b71Sopenharmony_ci## huks.finish<sup>(deprecated)</sup>
3703e41f4b71Sopenharmony_ci
3704e41f4b71Sopenharmony_cifinish(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
3705e41f4b71Sopenharmony_ci
3706e41f4b71Sopenharmony_ciFinishes the key operation. This API uses an asynchronous callback to return the result. **huks.init**, **huks.update**, and **huks.finish** must be used together.
3707e41f4b71Sopenharmony_ci
3708e41f4b71Sopenharmony_ci> **NOTE**
3709e41f4b71Sopenharmony_ci>
3710e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.finishSession<sup>9+</sup>](#huksfinishsession9).
3711e41f4b71Sopenharmony_ci
3712e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3713e41f4b71Sopenharmony_ci
3714e41f4b71Sopenharmony_ci**Parameters**
3715e41f4b71Sopenharmony_ci
3716e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                 |
3717e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------- |
3718e41f4b71Sopenharmony_ci| handle | number           | Yes  | Handle for the **finish** operation.|
3719e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Parameter set used for the **finish** operation.|
3720e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksResult](#huksresultdeprecated)> | Yes| Callback used to return the **finish** operation result.|
3721e41f4b71Sopenharmony_ci
3722e41f4b71Sopenharmony_ci## huks.finish<sup>(deprecated)</sup>
3723e41f4b71Sopenharmony_ci
3724e41f4b71Sopenharmony_cifinish(handle: number, options: HuksOptions) : Promise\<HuksResult>
3725e41f4b71Sopenharmony_ci
3726e41f4b71Sopenharmony_ciFinishes the key operation. This API uses a promise to return the result. **huks.init**, **huks.update**, and **huks.finish** must be used together.
3727e41f4b71Sopenharmony_ci
3728e41f4b71Sopenharmony_ci> **NOTE**
3729e41f4b71Sopenharmony_ci>
3730e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.finishSession<sup>9+</sup>](#huksfinishsession9-1).
3731e41f4b71Sopenharmony_ci
3732e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3733e41f4b71Sopenharmony_ci
3734e41f4b71Sopenharmony_ci**Parameters**
3735e41f4b71Sopenharmony_ci
3736e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                 |
3737e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------- |
3738e41f4b71Sopenharmony_ci| handle | number           | Yes  | Handle for the **finish** operation.|
3739e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Parameter set used for the **finish** operation.|
3740e41f4b71Sopenharmony_ci
3741e41f4b71Sopenharmony_ci**Return value**
3742e41f4b71Sopenharmony_ci
3743e41f4b71Sopenharmony_ci| Type                               | Description                                              |
3744e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
3745e41f4b71Sopenharmony_ci| Promise\<[HuksResult](#huksresultdeprecated)> | Promise used to return the result.|
3746e41f4b71Sopenharmony_ci
3747e41f4b71Sopenharmony_ci## huks.abort<sup>(deprecated)</sup>
3748e41f4b71Sopenharmony_ci
3749e41f4b71Sopenharmony_ciabort(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
3750e41f4b71Sopenharmony_ci
3751e41f4b71Sopenharmony_ciAborts the use of the key. This API uses an asynchronous callback to return the result.
3752e41f4b71Sopenharmony_ci
3753e41f4b71Sopenharmony_ci> **NOTE**
3754e41f4b71Sopenharmony_ci>
3755e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.abortSession<sup>9+</sup>](#huksabortsession9).
3756e41f4b71Sopenharmony_ci
3757e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3758e41f4b71Sopenharmony_ci
3759e41f4b71Sopenharmony_ci**Parameters**
3760e41f4b71Sopenharmony_ci
3761e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                 |
3762e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------- |
3763e41f4b71Sopenharmony_ci| handle | number           | Yes  | Handle for the **abort** operation.|
3764e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Parameter set used for the **abort** operation.|
3765e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HuksResult](#huksresultdeprecated)> | Yes| Callback used to return the **abort** operation result.|
3766e41f4b71Sopenharmony_ci
3767e41f4b71Sopenharmony_ci**Example**
3768e41f4b71Sopenharmony_ci
3769e41f4b71Sopenharmony_ci```ts
3770e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3771e41f4b71Sopenharmony_ci/* huks.init, huks.update, and huks.finish must be used together.
3772e41f4b71Sopenharmony_ci * If an error occurs in any of them, call huks.abort to terminate the use of the key.
3773e41f4b71Sopenharmony_ci *
3774e41f4b71Sopenharmony_ci * The following uses a 2048-bit RSA key as an example. The callback-based APIs are used.
3775e41f4b71Sopenharmony_ci */
3776e41f4b71Sopenharmony_ci
3777e41f4b71Sopenharmony_cilet keyAlias = "HuksDemoRSA";
3778e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = [];
3779e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
3780e41f4b71Sopenharmony_ci    properties: properties,
3781e41f4b71Sopenharmony_ci    inData: new Uint8Array(0)
3782e41f4b71Sopenharmony_ci};
3783e41f4b71Sopenharmony_cilet handle: number = 0;
3784e41f4b71Sopenharmony_cilet resultMessage = "";
3785e41f4b71Sopenharmony_ciasync function generateKey() {
3786e41f4b71Sopenharmony_ci    properties[0] = {
3787e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
3788e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_RSA
3789e41f4b71Sopenharmony_ci    };
3790e41f4b71Sopenharmony_ci    properties[1] = {
3791e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
3792e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048
3793e41f4b71Sopenharmony_ci    };
3794e41f4b71Sopenharmony_ci    properties[2] = {
3795e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
3796e41f4b71Sopenharmony_ci        value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT
3797e41f4b71Sopenharmony_ci    };
3798e41f4b71Sopenharmony_ci    properties[3] = {
3799e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PADDING,
3800e41f4b71Sopenharmony_ci        value: huks.HuksKeyPadding.HUKS_PADDING_OAEP
3801e41f4b71Sopenharmony_ci    };
3802e41f4b71Sopenharmony_ci    properties[4] = {
3803e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_DIGEST,
3804e41f4b71Sopenharmony_ci        value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
3805e41f4b71Sopenharmony_ci    };
3806e41f4b71Sopenharmony_ci    huks.generateKey(keyAlias, options);
3807e41f4b71Sopenharmony_ci}
3808e41f4b71Sopenharmony_cifunction stringToUint8Array(str: string) {
3809e41f4b71Sopenharmony_ci    let arr: number[] = [];
3810e41f4b71Sopenharmony_ci    for (let i = 0, j = str.length; i < j; ++i) {
3811e41f4b71Sopenharmony_ci        arr.push(str.charCodeAt(i));
3812e41f4b71Sopenharmony_ci    }
3813e41f4b71Sopenharmony_ci    let tmpUint8Array = new Uint8Array(arr);
3814e41f4b71Sopenharmony_ci    return tmpUint8Array;
3815e41f4b71Sopenharmony_ci}
3816e41f4b71Sopenharmony_ciasync function huksInit() {
3817e41f4b71Sopenharmony_ci    await huks.init(keyAlias, options).then((data) => {
3818e41f4b71Sopenharmony_ci        console.info(`test init data: ${JSON.stringify(data)}`);
3819e41f4b71Sopenharmony_ci        handle = data.handle;
3820e41f4b71Sopenharmony_ci    }).catch((err) => {
3821e41f4b71Sopenharmony_ci        console.error("test init err information: " + JSON.stringify(err))
3822e41f4b71Sopenharmony_ci    })
3823e41f4b71Sopenharmony_ci}
3824e41f4b71Sopenharmony_ciasync function huksUpdate() {
3825e41f4b71Sopenharmony_ci    options.inData = stringToUint8Array("huksHmacTest");
3826e41f4b71Sopenharmony_ci    await huks.update(handle, options.inData, options).then((data) => {
3827e41f4b71Sopenharmony_ci        if (data.errorCode === 0) {
3828e41f4b71Sopenharmony_ci            resultMessage += "update success!";
3829e41f4b71Sopenharmony_ci        } else {
3830e41f4b71Sopenharmony_ci            resultMessage += "update fail!";
3831e41f4b71Sopenharmony_ci        }
3832e41f4b71Sopenharmony_ci    });
3833e41f4b71Sopenharmony_ci    console.info(resultMessage);
3834e41f4b71Sopenharmony_ci}
3835e41f4b71Sopenharmony_cifunction huksFinish() {
3836e41f4b71Sopenharmony_ci    options.inData = stringToUint8Array("HuksDemoHMAC");
3837e41f4b71Sopenharmony_ci    huks.finish(handle, options).then((data) => {
3838e41f4b71Sopenharmony_ci        if (data.errorCode === 0) {
3839e41f4b71Sopenharmony_ci            resultMessage = "finish success!";
3840e41f4b71Sopenharmony_ci            console.info(resultMessage);
3841e41f4b71Sopenharmony_ci        } else {
3842e41f4b71Sopenharmony_ci            resultMessage = "finish fail errorCode: " + data.errorCode;
3843e41f4b71Sopenharmony_ci            console.error(resultMessage);
3844e41f4b71Sopenharmony_ci        }
3845e41f4b71Sopenharmony_ci    }).catch((err) => {
3846e41f4b71Sopenharmony_ci        resultMessage = "Failed to complete the key operation. catch errorMessage:" + JSON.stringify(err)
3847e41f4b71Sopenharmony_ci    });
3848e41f4b71Sopenharmony_ci}
3849e41f4b71Sopenharmony_ciasync function huksAbort() {
3850e41f4b71Sopenharmony_ci    new Promise<huks.HuksResult>((resolve, reject) => {
3851e41f4b71Sopenharmony_ci        huks.abort(handle, options, (err, data) => {
3852e41f4b71Sopenharmony_ci            console.info(`huksAbort data ${JSON.stringify(data)}`);
3853e41f4b71Sopenharmony_ci            console.error(`huksAbort err ${JSON.stringify(err)}`);
3854e41f4b71Sopenharmony_ci        });
3855e41f4b71Sopenharmony_ci    });
3856e41f4b71Sopenharmony_ci}
3857e41f4b71Sopenharmony_ci```
3858e41f4b71Sopenharmony_ci
3859e41f4b71Sopenharmony_ci## huks.abort<sup>(deprecated)</sup>
3860e41f4b71Sopenharmony_ci
3861e41f4b71Sopenharmony_ciabort(handle: number, options: HuksOptions) : Promise\<HuksResult>;
3862e41f4b71Sopenharmony_ci
3863e41f4b71Sopenharmony_ciAborts the use of the key. This API uses a promise to return the result.
3864e41f4b71Sopenharmony_ci
3865e41f4b71Sopenharmony_ci> **NOTE**
3866e41f4b71Sopenharmony_ci>
3867e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [huks.abortSession<sup>9+</sup>](#huksabortsession9-1).
3868e41f4b71Sopenharmony_ci
3869e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3870e41f4b71Sopenharmony_ci
3871e41f4b71Sopenharmony_ci**Parameters**
3872e41f4b71Sopenharmony_ci
3873e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                 |
3874e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------- |
3875e41f4b71Sopenharmony_ci| handle | number           | Yes  | Handle for the **abort** operation.|
3876e41f4b71Sopenharmony_ci| options  | [HuksOptions](#huksoptions) | Yes  | Parameter set used for the **abort** operation.|
3877e41f4b71Sopenharmony_ci
3878e41f4b71Sopenharmony_ci**Return value**
3879e41f4b71Sopenharmony_ci
3880e41f4b71Sopenharmony_ci| Type                               | Description                                              |
3881e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------------- |
3882e41f4b71Sopenharmony_ci| Promise\<[HuksResult](#huksresultdeprecated)> | Promise used to return the **abort** operation result.|
3883e41f4b71Sopenharmony_ci
3884e41f4b71Sopenharmony_ci**Example**
3885e41f4b71Sopenharmony_ci
3886e41f4b71Sopenharmony_ci```ts
3887e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit';
3888e41f4b71Sopenharmony_ci/* huks.init, huks.update, and huks.finish must be used together.
3889e41f4b71Sopenharmony_ci * If an error occurs in any of them, call huks.abort to terminate the use of the key.
3890e41f4b71Sopenharmony_ci *
3891e41f4b71Sopenharmony_ci * The following uses a 2048-bit RSA key as an example. The promise-based APIs are used.
3892e41f4b71Sopenharmony_ci */
3893e41f4b71Sopenharmony_cilet keyAlias = "HuksDemoRSA";
3894e41f4b71Sopenharmony_cilet properties: Array<huks.HuksParam> = [];
3895e41f4b71Sopenharmony_cilet options: huks.HuksOptions = {
3896e41f4b71Sopenharmony_ci    properties: properties,
3897e41f4b71Sopenharmony_ci    inData: new Uint8Array(0)
3898e41f4b71Sopenharmony_ci};
3899e41f4b71Sopenharmony_cilet handle: number = 0;
3900e41f4b71Sopenharmony_cilet resultMessage = "";
3901e41f4b71Sopenharmony_ci
3902e41f4b71Sopenharmony_cifunction stringToUint8Array(str: string) {
3903e41f4b71Sopenharmony_ci    let arr: number[] = [];
3904e41f4b71Sopenharmony_ci    for (let i = 0, j = str.length; i < j; ++i) {
3905e41f4b71Sopenharmony_ci        arr.push(str.charCodeAt(i));
3906e41f4b71Sopenharmony_ci    }
3907e41f4b71Sopenharmony_ci    let tmpUint8Array = new Uint8Array(arr);
3908e41f4b71Sopenharmony_ci    return tmpUint8Array;
3909e41f4b71Sopenharmony_ci}
3910e41f4b71Sopenharmony_ci
3911e41f4b71Sopenharmony_ciasync function generateKey() {
3912e41f4b71Sopenharmony_ci    properties[0] = {
3913e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
3914e41f4b71Sopenharmony_ci        value: huks.HuksKeyAlg.HUKS_ALG_RSA
3915e41f4b71Sopenharmony_ci    };
3916e41f4b71Sopenharmony_ci    properties[1] = {
3917e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
3918e41f4b71Sopenharmony_ci        value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048
3919e41f4b71Sopenharmony_ci    };
3920e41f4b71Sopenharmony_ci    properties[2] = {
3921e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PURPOSE,
3922e41f4b71Sopenharmony_ci        value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT
3923e41f4b71Sopenharmony_ci    };
3924e41f4b71Sopenharmony_ci    properties[3] = {
3925e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_PADDING,
3926e41f4b71Sopenharmony_ci        value: huks.HuksKeyPadding.HUKS_PADDING_OAEP
3927e41f4b71Sopenharmony_ci    };
3928e41f4b71Sopenharmony_ci    properties[4] = {
3929e41f4b71Sopenharmony_ci        tag: huks.HuksTag.HUKS_TAG_DIGEST,
3930e41f4b71Sopenharmony_ci        value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
3931e41f4b71Sopenharmony_ci    };
3932e41f4b71Sopenharmony_ci    huks.generateKey(keyAlias, options, (err, data) => {
3933e41f4b71Sopenharmony_ci    });
3934e41f4b71Sopenharmony_ci}
3935e41f4b71Sopenharmony_ci
3936e41f4b71Sopenharmony_ciasync function huksInit() {
3937e41f4b71Sopenharmony_ci    return new Promise<huks.HuksHandle>((resolve, reject) => {
3938e41f4b71Sopenharmony_ci        huks.init(keyAlias, options, async (err, data) => {
3939e41f4b71Sopenharmony_ci            if (data.errorCode === 0) {
3940e41f4b71Sopenharmony_ci                resultMessage = "init success!"
3941e41f4b71Sopenharmony_ci                handle = data.handle;
3942e41f4b71Sopenharmony_ci            } else {
3943e41f4b71Sopenharmony_ci                resultMessage = "init fail errorCode: " + data.errorCode
3944e41f4b71Sopenharmony_ci            }
3945e41f4b71Sopenharmony_ci        });
3946e41f4b71Sopenharmony_ci    });
3947e41f4b71Sopenharmony_ci}
3948e41f4b71Sopenharmony_ci
3949e41f4b71Sopenharmony_ciasync function huksUpdate() {
3950e41f4b71Sopenharmony_ci    options.inData = stringToUint8Array("huksHmacTest");
3951e41f4b71Sopenharmony_ci    new Promise<huks.HuksResult>((resolve, reject) => {
3952e41f4b71Sopenharmony_ci        huks.update(handle, options.inData, options, (err, data) => {
3953e41f4b71Sopenharmony_ci            if (data.errorCode === 0) {
3954e41f4b71Sopenharmony_ci                resultMessage += "update success!";
3955e41f4b71Sopenharmony_ci                console.info(resultMessage);
3956e41f4b71Sopenharmony_ci            } else {
3957e41f4b71Sopenharmony_ci                resultMessage += "update fail!";
3958e41f4b71Sopenharmony_ci                console.error(resultMessage);
3959e41f4b71Sopenharmony_ci            }
3960e41f4b71Sopenharmony_ci        });
3961e41f4b71Sopenharmony_ci    });
3962e41f4b71Sopenharmony_ci
3963e41f4b71Sopenharmony_ci}
3964e41f4b71Sopenharmony_ci
3965e41f4b71Sopenharmony_ciasync function huksFinish() {
3966e41f4b71Sopenharmony_ci    options.inData = stringToUint8Array("0");
3967e41f4b71Sopenharmony_ci    new Promise<huks.HuksResult>((resolve, reject) => {
3968e41f4b71Sopenharmony_ci        huks.finish(handle, options, (err, data) => {
3969e41f4b71Sopenharmony_ci            if (data.errorCode === 0) {
3970e41f4b71Sopenharmony_ci                resultMessage = "finish success!";
3971e41f4b71Sopenharmony_ci            } else {
3972e41f4b71Sopenharmony_ci                resultMessage = "finish fail errorCode: " + data.errorCode;
3973e41f4b71Sopenharmony_ci            }
3974e41f4b71Sopenharmony_ci        });
3975e41f4b71Sopenharmony_ci    });
3976e41f4b71Sopenharmony_ci}
3977e41f4b71Sopenharmony_ci
3978e41f4b71Sopenharmony_cifunction huksAbort() {
3979e41f4b71Sopenharmony_ci    huks.abort(handle, options).then((data) => {
3980e41f4b71Sopenharmony_ci        if (data.errorCode === 0) {
3981e41f4b71Sopenharmony_ci            console.info("abort success!");
3982e41f4b71Sopenharmony_ci        } else {
3983e41f4b71Sopenharmony_ci            console.error("abort fail errorCode: " + data.errorCode);
3984e41f4b71Sopenharmony_ci        }
3985e41f4b71Sopenharmony_ci    }).catch((err: Error) => {
3986e41f4b71Sopenharmony_ci        console.error("abort fail, catch errorMessage:" + JSON.stringify(err));
3987e41f4b71Sopenharmony_ci    });
3988e41f4b71Sopenharmony_ci}
3989e41f4b71Sopenharmony_ci```
3990e41f4b71Sopenharmony_ci
3991e41f4b71Sopenharmony_ci## HuksHandle<sup>(deprecated)</sup>
3992e41f4b71Sopenharmony_ci
3993e41f4b71Sopenharmony_ciDefines the struct for a HUKS handle.
3994e41f4b71Sopenharmony_ci
3995e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
3996e41f4b71Sopenharmony_ci
3997e41f4b71Sopenharmony_ci> **NOTE**
3998e41f4b71Sopenharmony_ci>
3999e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [HuksSessionHandle<sup>9+</sup>](#hukssessionhandle9).
4000e41f4b71Sopenharmony_ci
4001e41f4b71Sopenharmony_ci| Name    | Type            | Mandatory| Description    |
4002e41f4b71Sopenharmony_ci| ---------- | ---------------- | ---- | -------- |
4003e41f4b71Sopenharmony_ci| errorCode  | number           | Yes  | Error code.|
4004e41f4b71Sopenharmony_ci| handle    | number       | Yes| Value of the handle.|
4005e41f4b71Sopenharmony_ci| token | Uint8Array | No| Challenge obtained after the [init](#huksinitdeprecated) operation.|
4006e41f4b71Sopenharmony_ci
4007e41f4b71Sopenharmony_ci## HuksResult<sup>(deprecated)</sup>
4008e41f4b71Sopenharmony_ci
4009e41f4b71Sopenharmony_ciDefines the **HuksResult** struct.
4010e41f4b71Sopenharmony_ci
4011e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
4012e41f4b71Sopenharmony_ci
4013e41f4b71Sopenharmony_ci> **NOTE**
4014e41f4b71Sopenharmony_ci>
4015e41f4b71Sopenharmony_ci> - This API is deprecated since API version 9. You are advised to use [HuksReturnResult<sup>9+</sup>](#huksreturnresult9).
4016e41f4b71Sopenharmony_ci> - For details about the error codes, see [HUKS Error Codes](errorcode-huks.md).
4017e41f4b71Sopenharmony_ci
4018e41f4b71Sopenharmony_ci| Name    | Type                           | Mandatory| Description            |
4019e41f4b71Sopenharmony_ci| ---------- | ------------------------------- | ---- | ---------------- |
4020e41f4b71Sopenharmony_ci| errorCode  | number                          | Yes  | Error code.    |
4021e41f4b71Sopenharmony_ci| outData    | Uint8Array                      | No  | Output data.  |
4022e41f4b71Sopenharmony_ci| properties | Array\<[HuksParam](#huksparam)> | No  | Property information.  |
4023e41f4b71Sopenharmony_ci| certChains | Array\<string>                  | No  | Certificate chain information.|
4024e41f4b71Sopenharmony_ci
4025e41f4b71Sopenharmony_ci## HuksErrorCode<sup>(deprecated)</sup>
4026e41f4b71Sopenharmony_ci
4027e41f4b71Sopenharmony_ciEnumerates the error codes.
4028e41f4b71Sopenharmony_ci
4029e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.Huks.Extension
4030e41f4b71Sopenharmony_ci
4031e41f4b71Sopenharmony_ci> **NOTE**
4032e41f4b71Sopenharmony_ci>
4033e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [HuksExceptionErrCode<sup>9+</sup>](#huksexceptionerrcode9).
4034e41f4b71Sopenharmony_ci
4035e41f4b71Sopenharmony_ci| Name                      | Value   | Description|
4036e41f4b71Sopenharmony_ci| -------------------------- | ----- | ---- |
4037e41f4b71Sopenharmony_ci| HUKS_SUCCESS | 0     |Success.|
4038e41f4b71Sopenharmony_ci| HUKS_FAILURE | -1    |Failure.|
4039e41f4b71Sopenharmony_ci| HUKS_ERROR_BAD_STATE | -2    |Incorrect state.|
4040e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_ARGUMENT | -3    |Invalid argument.|
4041e41f4b71Sopenharmony_ci| HUKS_ERROR_NOT_SUPPORTED | -4    |Not supported.|
4042e41f4b71Sopenharmony_ci| HUKS_ERROR_NO_PERMISSION | -5    |No permission.|
4043e41f4b71Sopenharmony_ci| HUKS_ERROR_INSUFFICIENT_DATA | -6    |Insufficient data.|
4044e41f4b71Sopenharmony_ci| HUKS_ERROR_BUFFER_TOO_SMALL | -7    |Insufficient buffer.|
4045e41f4b71Sopenharmony_ci| HUKS_ERROR_INSUFFICIENT_MEMORY | -8    |Insufficient memory.|
4046e41f4b71Sopenharmony_ci| HUKS_ERROR_COMMUNICATION_FAILURE | -9    |Communication failure.|
4047e41f4b71Sopenharmony_ci| HUKS_ERROR_STORAGE_FAILURE | -10   |Insufficient storage space.|
4048e41f4b71Sopenharmony_ci| HUKS_ERROR_HARDWARE_FAILURE | -11   |Hardware fault.|
4049e41f4b71Sopenharmony_ci| HUKS_ERROR_ALREADY_EXISTS | -12   |The object already exists.|
4050e41f4b71Sopenharmony_ci| HUKS_ERROR_NOT_EXIST | -13   |The object does not exist.|
4051e41f4b71Sopenharmony_ci| HUKS_ERROR_NULL_POINTER | -14   |Null pointer.|
4052e41f4b71Sopenharmony_ci| HUKS_ERROR_FILE_SIZE_FAIL | -15   |Incorrect file size.|
4053e41f4b71Sopenharmony_ci| HUKS_ERROR_READ_FILE_FAIL | -16   |Failed to read the file.|
4054e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_PUBLIC_KEY | -17   |Invalid public key.|
4055e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_PRIVATE_KEY | -18   |Invalid private key.|
4056e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_KEY_INFO | -19   |Invalid key information.|
4057e41f4b71Sopenharmony_ci| HUKS_ERROR_HASH_NOT_EQUAL | -20   |The hash values are not equal.|
4058e41f4b71Sopenharmony_ci| HUKS_ERROR_MALLOC_FAIL | -21   |MALLOC failed.|
4059e41f4b71Sopenharmony_ci| HUKS_ERROR_WRITE_FILE_FAIL | -22   |Failed to write the file.|
4060e41f4b71Sopenharmony_ci| HUKS_ERROR_REMOVE_FILE_FAIL | -23   |Failed to delete the file.|
4061e41f4b71Sopenharmony_ci| HUKS_ERROR_OPEN_FILE_FAIL | -24   |Failed to open the file.|
4062e41f4b71Sopenharmony_ci| HUKS_ERROR_CLOSE_FILE_FAIL | -25   |Failed to close the file.|
4063e41f4b71Sopenharmony_ci| HUKS_ERROR_MAKE_DIR_FAIL | -26   |Failed to create the directory.|
4064e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_KEY_FILE | -27   |Invalid key file.|
4065e41f4b71Sopenharmony_ci| HUKS_ERROR_IPC_MSG_FAIL | -28   |Incorrect IPC information.|
4066e41f4b71Sopenharmony_ci| HUKS_ERROR_REQUEST_OVERFLOWS | -29   |Request overflows.|
4067e41f4b71Sopenharmony_ci| HUKS_ERROR_PARAM_NOT_EXIST | -30   |The parameter does not exist.|
4068e41f4b71Sopenharmony_ci| HUKS_ERROR_CRYPTO_ENGINE_ERROR | -31   |CRYPTO ENGINE error.|
4069e41f4b71Sopenharmony_ci| HUKS_ERROR_COMMUNICATION_TIMEOUT | -32   |Communication timed out.|
4070e41f4b71Sopenharmony_ci| HUKS_ERROR_IPC_INIT_FAIL | -33   |IPC initialization failed.|
4071e41f4b71Sopenharmony_ci| HUKS_ERROR_IPC_DLOPEN_FAIL | -34   |IPC DLOPEN failed.|
4072e41f4b71Sopenharmony_ci| HUKS_ERROR_EFUSE_READ_FAIL | -35   |Failed to read eFuse.|
4073e41f4b71Sopenharmony_ci| HUKS_ERROR_NEW_ROOT_KEY_MATERIAL_EXIST | -36   |New root key material exists.|
4074e41f4b71Sopenharmony_ci| HUKS_ERROR_UPDATE_ROOT_KEY_MATERIAL_FAIL | -37   |Failed to update the root key material.|
4075e41f4b71Sopenharmony_ci| HUKS_ERROR_VERIFICATION_FAILED | -38   |Failed to verify the certificate chain.|
4076e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_ALG_FAIL | -100  |Failed to obtain the ALG. |
4077e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_KEY_SIZE_FAIL | -101  |Failed to obtain the key size.|
4078e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_PADDING_FAIL | -102  |Failed to obtain the padding algorithm.|
4079e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_PURPOSE_FAIL | -103  |Failed to obtain the key purpose.|
4080e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_DIGEST_FAIL | -104  |Failed to obtain the digest algorithm.|
4081e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_MODE_FAIL | -105  |Failed to obtain the cipher mode.|
4082e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_NONCE_FAIL | -106  |Failed to obtain the nonce.|
4083e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_AAD_FAIL | -107  |Failed to obtain the AAD.|
4084e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_IV_FAIL | -108  |Failed to obtain the initialization vector (IV).|
4085e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_AE_TAG_FAIL | -109  |Failed to obtain the AE flag.|
4086e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_SALT_FAIL | -110  |Failed to obtain the salt value.|
4087e41f4b71Sopenharmony_ci| HUKS_ERROR_CHECK_GET_ITERATION_FAIL | -111  |Failed to obtain the number of iterations.|
4088e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_ALGORITHM | -112  |Invalid algorithm.|
4089e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_KEY_SIZE | -113  |Invalid key size.|
4090e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_PADDING | -114  |Invalid padding algorithm.|
4091e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_PURPOSE | -115  |Invalid key purpose.|
4092e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_MODE | -116  |Invalid cipher mode.|
4093e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_DIGEST | -117  |Invalid digest algorithm.|
4094e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_SIGNATURE_SIZE | -118  |Invalid signature size.|
4095e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_IV | -119  |Invalid IV.|
4096e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_AAD | -120  |Invalid AAD.|
4097e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_NONCE | -121  |Invalid nonce.|
4098e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_AE_TAG | -122  |Invalid AE tag.|
4099e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_SALT | -123  |Invalid salt value.|
4100e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_ITERATION | -124  |Invalid iteration count.|
4101e41f4b71Sopenharmony_ci| HUKS_ERROR_INVALID_OPERATION | -125  |Invalid operation.|
4102e41f4b71Sopenharmony_ci| HUKS_ERROR_INTERNAL_ERROR | -999  |Internal error.|
4103e41f4b71Sopenharmony_ci| HUKS_ERROR_UNKNOWN_ERROR | -1000 |Unknown error.|
4104