• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Obtaining Key Properties (ArkTS)
2
3
4This topic describes how to obtain properties of a key. Before the operation, ensure that the key exists in HUKS.
5
6## How to Develop
7
81. Set the key alias (**keyAlias**), which cannot exceed 128 bytes.
9
102. Use [getKeyItemProperties](../../reference/apis-universal-keystore-kit/js-apis-huks.md#huksgetkeyitemproperties9) to obtain the properties of the key based on **keyAlias** and **options**.
11   **options** is a reserved parameter and is left empty currently.
12
133. You can find the key properties in the **properties** field in the [HuksReturnResult](../../reference/apis-universal-keystore-kit/js-apis-huks.md#huksreturnresult9) object.
14
15```ts
16import { huks } from '@kit.UniversalKeystoreKit';
17
18/* 1. Set the key alias. */
19let keyAlias = 'keyAlias';
20/* Leave options empty. */
21let emptyOptions: huks.HuksOptions = {
22  properties: []
23};
24try {
25  /* 2. Obtain key properties. */
26  huks.getKeyItemProperties(keyAlias, emptyOptions, (error, data) => {
27    if (error) {
28      console.error(`callback: getKeyItemProperties failed, ` + JSON.stringify(error));
29    } else {
30      console.info(`callback: getKeyItemProperties success, data = ${JSON.stringify(data)}`);
31    }
32  });
33} catch (error) {
34  console.error(`callback: getKeyItemProperties input arg invalid, ` + JSON.stringify(error));
35}
36```
37