• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Deleting a Key (C/C++)
2
3
4To ensure data security, delete the key that is no longer required.
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
13For example, delete a 256-bit HKDF key.
14
151. Set the key alias (**keyAlias**), which cannot exceed 128 bytes. **paramSet** is a reserved parameter. Leave it empty.
16
172. Use [OH_Huks_DeleteKeyItem](../../reference/apis-universal-keystore-kit/_huks_key_api.md#oh_huks_deletekeyitem) to delete the key.
18
19```c++
20#include "huks/native_huks_api.h"
21#include "huks/native_huks_param.h"
22#include <string.h>
23static napi_value DeleteKey(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_DeleteKeyItem to delete the key. */
32    struct OH_Huks_Result ohResult = OH_Huks_DeleteKeyItem(&keyAlias, nullptr);
33
34    napi_value ret;
35    napi_create_int32(env, ohResult.errorCode, &ret);
36    return ret;
37}
38```
39