鸿蒙开发: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));
}
相关推荐
OH_TPC16 小时前
HarmonyOS APP开发---“智泊“智能停车App,需要用到这个库
华为·harmonyos·鸿蒙
tsqtsqtsq030920 小时前
鸿蒙应用开发配置文件详解
harmonyos
贾伟康21 小时前
【HarmonyOS 7新能力|066】弱网直播优化实战:从网络感知到码率、缓冲与恢复
音视频·harmonyos·arkts·网络优化·弱网直播
m0_738185821 天前
Flutter 鸿蒙化实战:flutter_exif_plugin 适配 OpenHarmony,图片 EXIF 读写
flutter·华为·harmonyos·鸿蒙
动物园猫1 天前
Compose Multiplatform 三方库 KoalaPlot(koalaplot-core)的 OpenHarmony 鸿蒙化适配实战
华为·harmonyos
resh_people1 天前
开源鸿蒙平台 KMP_CMP 三方库「AtomicFU」适配全流程
华为·开源·harmonyos
李游Leo1 天前
HarmonyOS 7 + ArkUI-Window Kit:闪控窗任务恢复与形态切换【鸿蒙心迹】
华为·harmonyos
李游Leo1 天前
HarmonyOS 7 + ArkUI-Hvigor:动态字体与色彩对比上架预检【鸿蒙心迹】
华为·log4j·harmonyos
李游Leo1 天前
HarmonyOS 7 ArkTS + ohpm:三方 JS 库副作用隔离与 API 26 升级回归【鸿蒙心迹】
javascript·回归·harmonyos
500841 天前
React Native for OpenHarmony 实战:三方库 react-native-crypto-js 的鸿蒙化适配指南
javascript·react native·性能优化·electron·harmonyos