Authentication Status Query (ArkTS)
From API version 22, huksExternalCrypto provides the API for querying the PIN authentication status. This API can be used by applications to query whether the PIN passes authentication. For details about the scenarios and specifications, see Ukey PIN Authentication Management Overview and Specifications.
How to Develop
-
Obtain keyUri as resourceId by calling the certificate selection API provided by the certificate management system.
-
Call getUkeyPinAuthState to verify the PIN.
Development Cases
import { huksExternalCrypto } from '@kit.UniversalKeystoreKit';
import { BusinessError } from '@kit.BasicServicesKit';
async function getUkeyPinAuthState(): Promise<huksExternalCrypto.HuksExternalPinAuthState> {
let ret: huksExternalCrypto.HuksExternalPinAuthState = huksExternalCrypto.HuksExternalPinAuthState.HUKS_EXT_CRYPTO_PIN_NO_AUTH;
try {
/* 1. Construct parameters for querying the PIN status.*/
const testResourceId = JSON.stringify({
providerName: "testProviderName",
bundleName: "com.example.cryptoapplication",
abilityName: "CryptoExtension",
index: {
key: "testKey"
} as ESObject
});
const extProperties: Array<huksExternalCrypto.HuksExternalCryptoParam> = [];
/* 2. Call getUkeyPinAuthState. */
await huksExternalCrypto.getUkeyPinAuthState(testResourceId, extProperties)
.then((data) => {
console.info(`promise: getUkeyPinAuthState success , data : ${data}`);
}).catch((error: BusinessError) => {
console.error(`promise: getUkeyPinAuthState failed, errCode : ${error.code}, errMsg : ${error.message}`);
});
} catch (error) {
console.error(`promise: getUkeyPinAuthState input arg invalid`);
}
return ret;
}
async function testGetUkeyPinAuthState() {
let ret: huksExternalCrypto.HuksExternalPinAuthState = await getUkeyPinAuthState();
if (ret != huksExternalCrypto.HuksExternalPinAuthState.HUKS_EXT_CRYPTO_PIN_AUTH_SUCCEEDED) {
console.error(`getUkeyPinAuthState failed`);
return;
}
console.info(`getUkeyPinAuthState success`);
}
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 huks-key-import-overview
openharmony 鸿蒙 huks-signing-signature-verification-arkts
openharmony 鸿蒙 huks-hmac-arkts
openharmony 鸿蒙 huks-key-agreement-overview
openharmony 鸿蒙 huks-as-user-sys
openharmony 鸿蒙 huks-delete-key-ndk
openharmony 鸿蒙 huks-check-key-ndk
openharmony 鸿蒙 huks-extension-registration-and-unregistration-arkts