鸿蒙开发: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));
}
相关推荐
●VON1 小时前
AtomGit Flutter鸿蒙客户端:文件树与代码浏览
android·服务器·安全·flutter·harmonyos·鸿蒙
molong9318 小时前
鸿蒙基础之数据api全解析
华为·harmonyos
李二。9 小时前
鸿蒙原生ArkTS-鸿蒙6.0新特性-动态模糊视频背景登录页
华为·音视频·harmonyos
李二。11 小时前
鸿蒙原生ArkTS-鸿蒙6.0新特性-粒子特效壁纸动态桌面
华为·harmonyos
科技与数码12 小时前
鸿蒙智能待办:钉钉学而思待办自动同步日历
华为·钉钉·harmonyos
不爱学英文的码字机器14 小时前
[鸿蒙PC命令行移植适配]移植rust三方库tokei到鸿蒙PC的完整实践
华为·rust·harmonyos
EterNity_TiMe_14 小时前
[鸿蒙PC命令行移植适配]移植rust三方库ouch到鸿蒙PC的完整实践
华为·rust·harmonyos
提子拌饭13314 小时前
路径动画用鸿蒙PC用Electron框架实现流动效果技术详解
华为·electron·开源·harmonyos·鸿蒙
李二。14 小时前
鸿蒙原生ArkTS通讯录管家实战开发详解
华为·harmonyos
EterNity_TiMe_15 小时前
[鸿蒙PC命令行移植适配]移植rust三方库broot到鸿蒙PC的完整实践
华为·rust·harmonyos