1e41f4b71Sopenharmony_ci# Deleting a Key (ArkTS) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciTo ensure data security, delete the key that is no longer required. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## How to Develop 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciFor example, delete a 256-bit HKDF key. 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 delete, for example, delete all keys or a single key. To delete a single key, leave **properties** empty. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci3. Use [deleteKeyItem](../../reference/apis-universal-keystore-kit/js-apis-huks.md#huksdeletekeyitem9) to delete the key. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ci/* 17e41f4b71Sopenharmony_ci * Delete a 256-bit HKDF key. This example uses promise-based APIs. 18e41f4b71Sopenharmony_ci */ 19e41f4b71Sopenharmony_ciimport { huks } from '@kit.UniversalKeystoreKit'; 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci/* 1. Set the key alias. */ 22e41f4b71Sopenharmony_cilet keyAlias = "test_Key"; 23e41f4b71Sopenharmony_ci/* 2. Construct an empty object. */ 24e41f4b71Sopenharmony_cilet huksOptions: huks.HuksOptions = { 25e41f4b71Sopenharmony_ci properties: [] 26e41f4b71Sopenharmony_ci} 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ciclass throwObject { 29e41f4b71Sopenharmony_ci isThrow = false; 30e41f4b71Sopenharmony_ci} 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_cifunction deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: throwObject) { 33e41f4b71Sopenharmony_ci return new Promise<void>((resolve, reject) => { 34e41f4b71Sopenharmony_ci try { 35e41f4b71Sopenharmony_ci huks.deleteKeyItem(keyAlias, huksOptions, (error, data) => { 36e41f4b71Sopenharmony_ci if (error) { 37e41f4b71Sopenharmony_ci reject(error); 38e41f4b71Sopenharmony_ci } else { 39e41f4b71Sopenharmony_ci resolve(data); 40e41f4b71Sopenharmony_ci } 41e41f4b71Sopenharmony_ci }); 42e41f4b71Sopenharmony_ci } catch (error) { 43e41f4b71Sopenharmony_ci throwObject.isThrow = true; 44e41f4b71Sopenharmony_ci throw (error as Error); 45e41f4b71Sopenharmony_ci } 46e41f4b71Sopenharmony_ci }); 47e41f4b71Sopenharmony_ci} 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci/* 3. Delete the key. */ 50e41f4b71Sopenharmony_ciasync function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { 51e41f4b71Sopenharmony_ci console.info(`enter promise deleteKeyItem`); 52e41f4b71Sopenharmony_ci let throwObject: throwObject = { isThrow: false }; 53e41f4b71Sopenharmony_ci try { 54e41f4b71Sopenharmony_ci await deleteKeyItem(keyAlias, huksOptions, throwObject) 55e41f4b71Sopenharmony_ci .then((data) => { 56e41f4b71Sopenharmony_ci console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); 57e41f4b71Sopenharmony_ci }) 58e41f4b71Sopenharmony_ci .catch((error: Error) => { 59e41f4b71Sopenharmony_ci if (throwObject.isThrow) { 60e41f4b71Sopenharmony_ci throw (error as Error); 61e41f4b71Sopenharmony_ci } else { 62e41f4b71Sopenharmony_ci console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`); 63e41f4b71Sopenharmony_ci } 64e41f4b71Sopenharmony_ci }); 65e41f4b71Sopenharmony_ci } catch (error) { 66e41f4b71Sopenharmony_ci console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`); 67e41f4b71Sopenharmony_ci } 68e41f4b71Sopenharmony_ci} 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ciasync function testDerive() { 71e41f4b71Sopenharmony_ci await publicDeleteKeyFunc(keyAlias, huksOptions); 72e41f4b71Sopenharmony_ci} 73e41f4b71Sopenharmony_ci``` 74