General Query (ArkTS)
From API version 22, huksExternalCrypto provides the general query API. This API can be used to obtain the device ID, application ID, and other general properties from an UKey. For details about the scenarios, see General Query Overview and Specifications.
How to Develop
Obtaining properties
-
Obtain keyUri as resourceId by calling the certificate selection API provided by the certificate management system, and open the resource.
-
Construct the input parameter propertyId and optional input parameter HuksExternalCryptoParam.
-
Call getProperty to obtain the property information.
Development Cases
import { huksExternalCrypto } from '@kit.UniversalKeystoreKit';
import { BusinessError } from '@kit.BasicServicesKit';
async function getProperty(): Promise<Array<huksExternalCrypto.HuksExternalCryptoParam>> {
// 1. Obtain resourceId. Assume that resourceId is as follows and the resource has been opened:
const testResourceId = JSON.stringify({
providerName: "testProviderName",
bundleName: "com.example.cryptoapplication",
abilityName: "CryptoExtension",
index: {
key: "testKey"
} as ESObject
});
// 2. Construct the input parameter propertyId and optional parameter HuksExternalCryptoParam.
let propertyId = "SKF_EnumDev";
const extProperties: Array<huksExternalCrypto.HuksExternalCryptoParam> = [];
// 3. Call getProperty to obtain the property information.
console.info(`promise: await huksExternalCrypto getProperty`);
try {
await huksExternalCrypto.getProperty(testResourceId, propertyId, extProperties)
.then((data) => {
console.info(`promise: getProperty success, data: ` + JSON.stringify(data));
}).catch((error: BusinessError) => {
console.error(`promise: getProperty failed, errCode : ${error.code}, errMsg : ${error.message}`);
})
} catch (error) {
console.error(`promise: getProperty failed, errCode : ${error.code}, errMsg : ${error.message}`);
}
return extProperties;
}
你可能感兴趣的鸿蒙文章
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