1# Checking a Key (C/C++)
2
3
4Check whether a key exists.
5
6## Add the dynamic library in the CMake script.
7```txt
8   target_link_libraries(entry PUBLIC libhuks_ndk.z.so)
9```
10
11## How to Develop
12
131. Construct the parameters.
14   - Set the key alias (**keyAlias**), which cannot exceed 128 bytes.
15   - Set the [tag](../../reference/apis-universal-keystore-kit/_huks_type_api.md#oh_huks_tag) of the key to check. By default, this parameter is left empty.
16
172. Use [OH_Huks_IsKeyItemExist](../../reference/apis-universal-keystore-kit/_huks_key_api.md#oh_huks_iskeyitemexist) to check whether the key exists.
18
19```c++
20#include "huks/native_huks_api.h"
21#include "huks/native_huks_param.h"
22#include <string.h>
23static napi_value IsKeyExist(napi_env env, napi_callback_info info)
24{
25    /* 1. Obtain the key alias. */
26    struct OH_Huks_Blob keyAlias = {
27        (uint32_t)strlen("test_key"),
28        (uint8_t *)"test_key"
29    };
30
31    /* 2. Call OH_Huks_IsKeyItemExist to check whether the key exists. */
32    struct OH_Huks_Result ohResult = OH_Huks_IsKeyItemExist(&keyAlias, nullptr);
33    // OH_HUKS_SUCCESS means the key exists, and OH_HUKS_ERR_CODE_ITEM_NOT_EXIST means the opposite.
34
35    napi_value ret;
36    napi_create_int32(env, ohResult.errorCode, &ret);
37    return ret;
38}
39```
40