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