鸿蒙开发: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));
}
相关推荐
如约见1 小时前
技术岗的「本科及以上」,多是软门槛
程序员·学历·技术岗
陈随易3 小时前
AI 运维服务器,安全又可靠的方法
前端·后端·程序员
青衫嵌入式4 小时前
根据 STM32 逐行拆解 FreeRTOS 的任务上下文切换
程序员
贾伟康4 小时前
【共创稿事节】HarmonyOS 7.0 AOT编译优化:从接入到生产验证
harmonyos·arkts·路由·navigation·navdestination
2601_949480065 小时前
开源鸿蒙平台 CMP 三方库「shadcn」适配全流程
华为·开源·harmonyos
Liaiyang667 小时前
空圈容错视角-HarmonyOS 7 架构体检:从被动容错到主动免疫的真伪验证与生态反推
操作系统·harmonyos·架构设计·ai-agent·端云协同·鸿蒙7·空圈容错
贾伟康7 小时前
【共创稿事节】HarmonyOS 7.0 Native XComponent与FFI:从接入到生产验证
harmonyos·profiler·hitracemeter·性能追踪·时间线
redtank20008 小时前
纯血鸿蒙本地电子书阅读器实测:九格式支持、沉浸阅读与零联网隐私设计
华为·harmonyos
贾伟康8 小时前
【共创稿事节】HarmonyOS 7.0 HiSysEvent系统事件订阅:从接入到生产验证
harmonyos·可观测性·hisyevent·系统事件·后台优化
独隅10 小时前
HarmonyOS 系统能力与体验深度评测 - 超详细版
华为·harmonyos