Checking a Key (ArkTS)
Check whether a key exists.
How to Develop
-
Set the key alias (keyAlias), which cannot exceed 128 bytes.
-
Initialize the key property set. You can specify HuksTag of the key to check. To check a single key, leave this parameter empty.
-
Use hasKeyItem to check whether the key exists.
import { huks } from '@kit.UniversalKeystoreKit';
/* 1. Set the key alias. */
let keyAlias = 'test_key';
let isKeyExist: Boolean;
/* 2. Construct an empty object. */
let huksOptions: huks.HuksOptions = {
properties: []
}
try {
/* 3. Check whether the key exists. */
huks.hasKeyItem(keyAlias, huksOptions, (error, data) => {
if (error) {
console.error(`callback: hasKeyItem failed, ` + JSON.stringify(error));
} else {
if (data !== null && data.valueOf() !== null) {
isKeyExist = data.valueOf();
console.info(`callback: hasKeyItem success, isKeyExist = ${isKeyExist}`);
}
}
});
} catch (error) {
console.error(`callback: hasKeyItem input arg invalid, ` + JSON.stringify(error));
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Universal Keystore Kit (Key Management Service)
harmony 鸿蒙Specifying the User for Key Operations (for System Applications Only)
harmony 鸿蒙Checking a Key (C/C++)
harmony 鸿蒙Basic Concepts of HUKS
harmony 鸿蒙Deleting a Key (ArkTS)
harmony 鸿蒙Deleting a Key (C/C++)
harmony 鸿蒙Encryption and Decryption (ArkTS)
harmony 鸿蒙Encryption and Decryption (C/C++)
harmony 鸿蒙Encryption and Decryption Overview and Algorithm Specifications