Obtaining Key Properties (ArkTS)
This topic describes how to obtain properties of a key. Before the operation, ensure that the key exists in HUKS.
NOTE
The mini-system devices do not support the operation for obtaining key properties.
How to Develop
-
Set the key alias (keyAlias), which cannot exceed 128 bytes.
-
Use getKeyItemProperties to obtain the properties of the key based on keyAlias and options. options is a reserved parameter and is left empty currently.
-
You can find the key properties in the properties field in the HuksReturnResult object.
import { huks } from '@kit.UniversalKeystoreKit';
/* 1. Set the key alias. */
let keyAlias = 'keyAlias';
/* Leave options empty. */
let emptyOptions: huks.HuksOptions = {
properties: []
};
try {
/* 2. Obtain key properties. */
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));
}