openharmony 鸿蒙 js-apis-huksExternalCrypto-sys

2026-08-25 浏览 (1)

@ohos.security.huksExternalCrypto (外部密钥管理)(系统接口)

模块提供外部密钥管理扩展功能的注册与注销,PIN码认证与认证状态获取等。

说明

本模块首批接口从API version 22开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import { huksExternalCrypto } from '@kit.UniversalKeystoreKit';

huksExternalCrypto.authUkeyPin

authUkeyPin(resourceId: string, params: Array<HuksExternalCryptoParam>): Promise<void>

PIN码认证。使用Promise异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.Security.Huks.CryptoExtension

参数:

参数名类型必填说明
resourceIdstringUkey中某容器的资源ID,可通过导出证书的接口获取,其结果中附带resourceId。
paramsArray<HuksExternalCryptoParam>操作时需传入的参数,必选TAG:HUKS_EXT_CRYPTO_TAG_UKEY_PIN

返回值:

类型说明
Promise<void>Promise对象,无返回结果。

错误码:

以下错误码的详细介绍请参见通用错误码HUKS错误码

错误码ID错误信息
202The caller is not a system application and is not allowed to use system applications.
801api is not supported.
12000005IPC communication failed.
12000006the Ukey driver operation failed.
12000011queried entity does not exist.
12000012Device environment or input parameter abnormal. This error may occur if the process function is not found, or due to other issues.
12000014memory is insufficient.
12000018the input parameter is invalid.
12000020the provider operation failed.
12000021the Ukey PIN is locked.
12000022the Ukey PIN is incorrect.
12000024the provider or Ukey is busy.

示例:

import { huksExternalCrypto } from '@kit.UniversalKeystoreKit';

function StringToUint8Array(str: string) {
  let arr: number[] = [];
  for (let i = 0, j = str.length; i < j; ++i) {
    arr.push(str.charCodeAt(i));
  }
  return new Uint8Array(arr);
}

let uid: number = 3511;
const testResourceId = "{\"providerName\":\"testProviderName\", \"bundleName\":\"com.example.cryptoapplication\", \"abilityName\":\"CryptoExtension\",\"index\":{\"key\":\"testKey\"}}";
const pin = "123456";
const extProperties: Array<huksExternalCrypto.HuksExternalCryptoParam> = [
  {
    tag: huksExternalCrypto.HuksExternalCryptoTag.HUKS_EXT_CRYPTO_TAG_UID,
    value: uid
  }, {
    tag: huksExternalCrypto.HuksExternalCryptoTag.HUKS_EXT_CRYPTO_TAG_UKEY_PIN,
    value: StringToUint8Array(pin)
  }
];
huksExternalCrypto.authUkeyPin(testResourceId, extProperties)
    .then((data) => {
        console.info(`promise: authUkeyPin success`);
    });

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-hukstypeapi-oh-huks-keymaterialrsa

openharmony 鸿蒙 capi-hukstypeapi-oh-huks-result

openharmony 鸿蒙 capi-native-huks-type-h

openharmony 鸿蒙 js-apis-CryptoExtensionAbility

openharmony 鸿蒙 capi-hukstypeapi-oh-huks-pubkeyinfo

openharmony 鸿蒙 capi-hukstypeapi-oh-huks-certchain

openharmony 鸿蒙 js-apis-huksExternalCrypto

openharmony 鸿蒙 capi-hukstypeapi-oh-huks-keymaterialdsa

openharmony 鸿蒙 Readme-CN

openharmony 鸿蒙 capi-hukstypeapi

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/PAmYtuWr