1e41f4b71Sopenharmony_ci# Checking a Key (ArkTS) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciCheck whether a key exists. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci## How to Develop 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci1. Set the key alias (**keyAlias**), which cannot exceed 128 bytes. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci2. Initialize the key property set to specify the properties of the key to check, for example, check all keys or a single key. To check a single key, leave **properties** empty. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci3. Use [hasKeyItem](../../reference/apis-universal-keystore-kit/js-apis-huks.md#hukshaskeyitem11) to check whether the key exists. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit'; 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci/* 1. Set the key alias. */ 19e41f4b71Sopenharmony_cilet keyAlias = 'test_key'; 20e41f4b71Sopenharmony_cilet isKeyExist: Boolean; 21e41f4b71Sopenharmony_ci/* 2. Construct an empty object. */ 22e41f4b71Sopenharmony_cilet huksOptions: huks.HuksOptions = { 23e41f4b71Sopenharmony_ci properties: [] 24e41f4b71Sopenharmony_ci} 25e41f4b71Sopenharmony_citry { 26e41f4b71Sopenharmony_ci /* 3. Check whether the key exists. */ 27e41f4b71Sopenharmony_ci huks.hasKeyItem(keyAlias, huksOptions, (error, data) => { 28e41f4b71Sopenharmony_ci if (error) { 29e41f4b71Sopenharmony_ci console.error(`callback: hasKeyItem failed, ` + JSON.stringify(error)); 30e41f4b71Sopenharmony_ci } else { 31e41f4b71Sopenharmony_ci if (data !== null && data.valueOf() !== null) { 32e41f4b71Sopenharmony_ci isKeyExist = data.valueOf(); 33e41f4b71Sopenharmony_ci console.info(`callback: hasKeyItem success, isKeyExist = ${isKeyExist}`); 34e41f4b71Sopenharmony_ci } 35e41f4b71Sopenharmony_ci } 36e41f4b71Sopenharmony_ci }); 37e41f4b71Sopenharmony_ci} catch (error) { 38e41f4b71Sopenharmony_ci console.error(`callback: hasKeyItem input arg invalid, ` + JSON.stringify(error)); 39e41f4b71Sopenharmony_ci} 40e41f4b71Sopenharmony_ci``` 41