鸿蒙开发:Universal Keystore Kit(密钥管理服务)【获取密钥属性(ArkTS)】

获取密钥属性(ArkTS)

HUKS提供了接口供业务获取指定密钥的相关属性。在获取指定密钥属性前,需要确保已在HUKS中生成或导入持久化存储的密钥。

开发步骤

  1. 指定待查询的密钥别名keyAlias,密钥别名最大长度为64字节。
  2. 调用接口[getKeyItemProperties],传入参数keyAlias和options。 options为预留参数,当前可传入空。
  3. 返回值为[HuksReturnResult]类型对象,获取的属性集在properties字段中。
`HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿`
import { huks } from '@kit.UniversalKeystoreKit';

/* 1. 设置密钥别名 */
let keyAlias = 'keyAlias';
/* option对象传空 */
let emptyOptions: huks.HuksOptions = {
  properties: []
};
try {
  /* 2. 获取密钥属性 */
  huks.getKeyItemProperties(keyAlias, emptyOptions, (error, data) => {
    if (error) {
      console.error(`callback: getKeyItemProperties failed, ` + JSON.stringify(error));
    } else {
      console.info(`callback: getKeyItemProperties success, data = ${JSON.stringify(data)}`);
    }
  });
} catch (error) {
  console.error(`callback: getKeyItemProperties input arg invalid, ` + JSON.stringify(error));
}
相关推荐
恋猫de小郭6 小时前
鸿蒙版 React Native 正式开源,ohos_react_native 了解一下
react native·react.js·harmonyos
OH五星上将7 小时前
OpenHarmony(鸿蒙南向开发)——小型系统芯片移植指南(二)
驱动开发·harmonyos·内存管理·openharmony·鸿蒙内核·鸿蒙源码·鸿蒙移植
让开,我要吃人了7 小时前
OpenHarmony鸿蒙开发( Beta5.0)智能油烟机开发实践
驱动开发·嵌入式硬件·华为·移动开发·harmonyos·鸿蒙·openharmony
OH五星上将7 小时前
OpenHarmony(鸿蒙南向开发)——轻量系统芯片移植指南(二)
嵌入式硬件·移动开发·harmonyos·移植·openharmony·鸿蒙开发
Andy醒16 小时前
HarmonyOS开发之使用Picker(从相册选择图片),并且通过Swiper组件实现图片预览
harmonyos·鸿蒙
张帅涛_6661 天前
HarmonyOS开发之全局状态管理
华为·harmonyos
让开,我要吃人了1 天前
HarmonyOS开发实战( Beta5.0)蓝牙实现服务端和客户端通讯详解
开发语言·前端·华为·移动开发·harmonyos·鸿蒙·鸿蒙系统
让开,我要吃人了1 天前
HarmonyOS应用开发( Beta5.0)HOS-用户认证服务:面部识别
服务器·前端·华为·移动开发·嵌入式·harmonyos·鸿蒙
让开,我要吃人了1 天前
HarmonyOS开发实战( Beta5.0)橡皮擦案例实践详解
开发语言·前端·华为·移动开发·harmonyos·鸿蒙·鸿蒙系统
ImomoTo1 天前
HarmonyOS学习(十一)——安全管理
学习·安全·harmonyos·arkts·arkui