1# Checking a Key (C/C++) 2 3 4Check whether a key exists. 5 6 7## How to Develop 8 91. Construct the parameters. 10 - Set the key alias (**keyAlias**), which cannot exceed 64 bytes. 11 - Set **TAG** of the key. By default, leave this parameter empty. 12 132. Use [OH_Huks_IsKeyItemExist](../../reference/apis-universal-keystore-kit/_huks_key_api.md#oh_huks_iskeyitemexist) to check whether the key exists. 14 15```c++ 16#include "huks/native_huks_api.h" 17#include "huks/native_huks_param.h" 18#include <string.h> 19static napi_value IsKeyExist(napi_env env, napi_callback_info info) 20{ 21 /* 1. Obtain the key alias. */ 22 struct OH_Huks_Blob keyAlias = { 23 (uint32_t)strlen("test_key"), 24 (uint8_t *)"test_key" 25 }; 26 27 /* 2. Call OH_Huks_IsKeyItemExist to check whether the key exists. */ 28 struct OH_Huks_Result ohResult = OH_Huks_IsKeyItemExist(&keyAlias, nullptr); 29 // OH_HUKS_SUCCESS means the key exists, and OH_HUKS_ERR_CODE_ITEM_NOT_EXIST means the opposite. 30 31 napi_value ret; 32 napi_create_int32(env, ohResult.errorCode, &ret); 33 return ret; 34} 35``` 36