harmony 鸿蒙Obtaining Key Properties (C/C++)
Obtaining Key Properties (C/C++)
This topic describes how to obtain properties of a key. Before the operation, ensure that the key exists in HUKS.
>NOTE
> The mini-system devices do not support the operation for obtaining key properties.
Add the dynamic library in the CMake script.
target_link_libraries(entry PUBLIC libhuks_ndk.z.so)
How to Develop
Set parameters.
- keyAlias: key alias encapsulated in an OH_Huks_Blob struct. The maximum length of the key alias is 128 bytes.
- paramSetIn: This parameter is reserved. Leave it empty.
- paramSetOut: result set used to hold the key properties obtained. It is an object of the OH_Huks_ParamSet type. Ensure that there is enough memory for storing the key properties obtained.
Use OH_Huks_GetKeyItemParamSet to obtain key properties.
Check the return value. If the operation is successful, obtain the key properties from paramSetOut. If the operation fails, an error code is returned.
#include "huks/native_huks_api.h"
#include "huks/native_huks_param.h"
#include <string.h>
static napi_value GetKeyParamSet(napi_env env, napi_callback_info info)
{
/* 1. Set the key alias. */
const char *alias = "test_key";
struct OH_Huks_Blob aliasBlob = { .size = (uint32_t)strlen(alias), .data = (uint8_t *)alias };
/* Request memory for outParamSet. */
struct OH_Huks_ParamSet *outParamSet = (struct OH_Huks_ParamSet *)malloc(512); // Request memory based on service requirements.
if (outParamSet == nullptr) {
return nullptr;
}
outParamSet->paramSetSize = 512;
struct OH_Huks_Result ohResult;
do {
/* 2. Obtain the key properties. */
ohResult = OH_Huks_GetKeyItemParamSet(&aliasBlob, nullptr, outParamSet);
if (ohResult.errorCode != OH_HUKS_SUCCESS) {
break;
}
/* 3. Read key properties from outParamSet. For example, obtain OH_HUKS_TAG_PURPOSE. */
OH_Huks_Param *purposeParam = nullptr; // No memory needs to be requested. After the parameter is obtained, the pointer points to the memory address of the parameter in the parameter set.
ohResult = OH_Huks_GetParam(outParamSet, OH_HUKS_TAG_PURPOSE, &purposeParam);
if (ohResult.errorCode != OH_HUKS_SUCCESS) {
break;
}
} while (0);
OH_Huks_FreeParamSet(&outParamSet);
napi_value ret;
napi_create_int32(env, ohResult.errorCode, &ret);
return ret;
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Universal Keystore Kit (Key Management Service)
harmony 鸿蒙Specifying the User for Key Operations (for System Applications Only)
harmony 鸿蒙Checking a Key (ArkTS)
harmony 鸿蒙Checking a Key (C/C++)
harmony 鸿蒙Basic Concepts of HUKS
harmony 鸿蒙Deleting a Key (ArkTS)
harmony 鸿蒙Deleting a Key (C/C++)
harmony 鸿蒙Encryption and Decryption (ArkTS)
harmony 鸿蒙Encryption and Decryption (C/C++)
harmony 鸿蒙Encryption and Decryption Overview and Algorithm Specifications
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦