openharmony 鸿蒙 js-apis-huksExternalCrypto-sys

2026-08-25 浏览 (1)

@ohos.security.huksExternalCrypto (External Key Management) (System API)

Provides the functionalities such as registration and deregistration of external key management extension, PIN authentication, and acquisition of authentication state.

Description

The initial APIs of this module are supported since API version 22. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

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

huksExternalCrypto.authUkeyPin

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

Authenticates a Ukey PIN. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Security.Huks.CryptoExtension

Parameters

NameTypeMandatoryDescription
resourceIdstringYesResource ID of a container in the Ukey, which can be obtained using certificateManagerDialog.openAuthorizeDialog22+. The result contains resourceId.
paramsArray<HuksExternalCryptoParam>YesParameters to be passed during the operation. The mandatory tag is HUKS_EXT_CRYPTO_TAG_UKEY_PIN.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and HUKS Error Codes.

IDError Message
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.

Example

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 鸿蒙 capi-hukstypeapi

openharmony 鸿蒙 errorcode-huks

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