• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 获取密钥属性(ArkTS)
2
3
4HUKS提供了接口供业务获取指定密钥的相关属性。在获取指定密钥属性前,需要确保已在HUKS中生成或导入持久化存储的密钥。
5
6
7## 开发步骤
8
91. 指定待查询的密钥别名keyAlias,密钥别名最大长度为64字节。
10
112. 调用接口[getKeyItemProperties](../../reference/apis-universal-keystore-kit/js-apis-huks.md#huksgetkeyitemproperties9),传入参数keyAlias和options。
12   options为预留参数,当前可传入空。
13
143. 返回值为[HuksReturnResult](../../reference/apis-universal-keystore-kit/js-apis-huks.md#huksreturnresult9)类型对象,获取的属性集在properties字段中。
15
16```ts
17import huks from '@ohos.security.huks';
18/* 1. 设置密钥别名 */
19let keyAlias = 'keyAlias';
20/* option对象传空 */
21let emptyOptions: huks.HuksOptions = {
22    properties: []
23};
24try {
25    /* 2. 获取密钥属性 */
26    huks.getKeyItemProperties(keyAlias, emptyOptions, (error, data) => {
27        if (error) {
28            console.error(`callback: getKeyItemProperties failed` + 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` + error);
35}
36```
37