鸿蒙开发: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));
}
相关推荐
less_1213844 分钟前
鸿蒙 WPS Open SDK 接入指南:凭据申请、HAR 集成与 registerApp 校验
华为·harmonyos·wps
Hilaku1 小时前
为什么我在团队里禁止使用 axios?
前端·javascript·程序员
SimonKing2 小时前
别再找笔记了,试试这款轻量级的开源软件:local-notes
后端·程序员·开源
威哥爱编程16 小时前
HarmonyOS 7 Agent 开发实战 07:多 Agent 任务分解与反思
agent·harmonyos
威哥爱编程16 小时前
HarmonyOS 7 Agent 开发实战 06:Agent 记忆与上下文管理
agent·harmonyos
程序员cxuan18 小时前
我用 WorkBuddy + ima 把公众号文章做成了知识库。
人工智能·后端·程序员
程序员cxuan19 小时前
玩了一天 REA,我号快没了
人工智能·后端·程序员
HarmonyOS_SDK20 小时前
【HarmonyOS SDK Skills】扫码能力一键构建,系统级高精度扫码秒实现
harmonyos
结局无敌1 天前
React Native for OpenHarmony 实战:三方库 react-native-modal-dialog 的鸿蒙化适配指南
深度学习·算法·react native·react.js·harmonyos
高晶1 天前
CANopen 在 BMS 系统中的 C 语言实战指南
设计模式·程序员