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