1e41f4b71Sopenharmony_ci# HuksKeyApi 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## 概述 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci描述HUKS向应用提供密钥库能力,包括密钥管理及密钥的密码学操作等功能。 管理的密钥可以由应用导入或者由应用调用HUKS接口生成。 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.Huks 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci**起始版本:** 9 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## 汇总 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci### 文件 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci| 名称 | 描述 | 19e41f4b71Sopenharmony_ci| -------- | -------- | 20e41f4b71Sopenharmony_ci| [native_huks_api.h](native__huks__api_8h.md) | 声明用于访问HUKS的API。<br>**引用文件**:<huks/native_huks_api.h> <br>**库**:libhuks_ndk.z.so | 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci### 函数 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| 名称 | 描述 | 26e41f4b71Sopenharmony_ci| -------- | -------- | 27e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_GetSdkVersion](#oh_huks_getsdkversion) (struct [OH_Huks_Blob](_o_h___huks___blob.md) \*sdkVersion) | 获取当前Huks sdk版本号。 | 28e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_GenerateKeyItem](#oh_huks_generatekeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSetIn, struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSetOut) | 生成密钥。 | 29e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_ImportKeyItem](#oh_huks_importkeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*key) | 导入明文密钥。 | 30e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_ImportWrappedKeyItem](#oh_huks_importwrappedkeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*wrappingKeyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*wrappedKeyData) | 导入密文密钥。 | 31e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_ExportPublicKeyItem](#oh_huks_exportpublickeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*key) | 导出公钥。 | 32e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_DeleteKeyItem](#oh_huks_deletekeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet) | 删除密钥。 | 33e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_GetKeyItemParamSet](#oh_huks_getkeyitemparamset) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSetIn, struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSetOut) | 获取密钥的属性集。 | 34e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_IsKeyItemExist](#oh_huks_iskeyitemexist) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet) | 判断密钥是否存在。 | 35e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_AttestKeyItem](#oh_huks_attestkeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, struct [OH_Huks_CertChain](_o_h___huks___cert_chain.md) \*certChain) | 获取密钥证书链。 | 36e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_AnonAttestKeyItem](#oh_huks_anonattestkeyitem) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, struct [OH_Huks_CertChain](_o_h___huks___cert_chain.md) \*certChain) | 获取密钥证书链。 | 37e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_InitSession](#oh_huks_initsession) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*keyAlias, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*handle, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*token) | 初始化密钥会话接口,并获取一个句柄(必选)和挑战值(可选)。 | 38e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_UpdateSession](#oh_huks_updatesession) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*handle, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*inData, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*outData) | 分段添加密钥操作的数据并进行相应的密钥操作,输出处理数据。 | 39e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_FinishSession](#oh_huks_finishsession) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*handle, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*inData, struct [OH_Huks_Blob](_o_h___huks___blob.md) \*outData) | 结束密钥会话并进行相应的密钥操作,输出处理数据。 | 40e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_AbortSession](#oh_huks_abortsession) (const struct [OH_Huks_Blob](_o_h___huks___blob.md) \*handle, const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet) | 取消密钥会话。 | 41e41f4b71Sopenharmony_ci| struct [OH_Huks_Result](_o_h___huks___result.md) [OH_Huks_ListAliases](#oh_huks_listaliases) (const struct [OH_Huks_ParamSet](_o_h___huks___param_set.md) \*paramSet, struct [OH_Huks_KeyAliasSet](_o_h___huks___key_alias_set.md) \*\*outData) | 批量查询密钥别名集。 | 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci## 函数说明 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci### OH_Huks_AbortSession() 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci``` 50e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_AbortSession (const struct OH_Huks_Blob * handle, const struct OH_Huks_ParamSet * paramSet ) 51e41f4b71Sopenharmony_ci``` 52e41f4b71Sopenharmony_ci**描述** 53e41f4b71Sopenharmony_ci取消密钥会话。 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci**起始版本:** 9 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**参数:** 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci| 名称 | 描述 | 60e41f4b71Sopenharmony_ci| -------- | -------- | 61e41f4b71Sopenharmony_ci| handle | 密钥会话句柄,通过[OH_Huks_InitSession](#oh_huks_initsession)接口生成的。 | 62e41f4b71Sopenharmony_ci| paramSet | 取消密钥会话需要的输入参数集(默认传空)。 | 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci**返回:** 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**参见:** 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci[OH_Huks_InitSession](#oh_huks_initsession) 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci[OH_Huks_UpdateSession](#oh_huks_updatesession) 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci[OH_Huks_FinishSession](#oh_huks_finishsession) 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci### OH_Huks_AnonAttestKeyItem() 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci``` 80e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_AnonAttestKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet, struct OH_Huks_CertChain * certChain ) 81e41f4b71Sopenharmony_ci``` 82e41f4b71Sopenharmony_ci**描述** 83e41f4b71Sopenharmony_ci获取密钥证书链。 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**起始版本:** 11 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci**参数:** 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci| 名称 | 描述 | 90e41f4b71Sopenharmony_ci| -------- | -------- | 91e41f4b71Sopenharmony_ci| keyAlias | 要获取证书的密钥的别名。 | 92e41f4b71Sopenharmony_ci| paramSet | 获取密钥证书需要的参数。 | 93e41f4b71Sopenharmony_ci| certChain | 存放输出的密钥证书链。 | 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**返回:** 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时获取成功,其他时为错误。 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**注解:** 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci这是一个涉及网络的耗时接口,调用方可以通过异步线程获取证书链。 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci### OH_Huks_AttestKeyItem() 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci``` 107e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_AttestKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet, struct OH_Huks_CertChain * certChain ) 108e41f4b71Sopenharmony_ci``` 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**描述** 111e41f4b71Sopenharmony_ci获取密钥证书链。 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**需要权限:** 114e41f4b71Sopenharmony_ciohos.permission.ATTEST_KEY,该权限仅系统应用可申请。 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**起始版本:** 9 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**参数:** 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci| 名称 | 描述 | 121e41f4b71Sopenharmony_ci| -------- | -------- | 122e41f4b71Sopenharmony_ci| keyAlias | 要获取证书的密钥的别名。 | 123e41f4b71Sopenharmony_ci| paramSet | 获取密钥证书需要的参数。 | 124e41f4b71Sopenharmony_ci| certChain | 存放输出的密钥证书链。 | 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**返回:** 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时获取成功,其他时为错误。 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci### OH_Huks_DeleteKeyItem() 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci``` 134e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_DeleteKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet ) 135e41f4b71Sopenharmony_ci``` 136e41f4b71Sopenharmony_ci**描述** 137e41f4b71Sopenharmony_ci删除密钥。 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**起始版本:** 9 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**参数:** 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci| 名称 | 描述 | 144e41f4b71Sopenharmony_ci| -------- | -------- | 145e41f4b71Sopenharmony_ci| keyAlias | 待删除密钥的别名,应与密钥生成时使用的别名相同。 | 146e41f4b71Sopenharmony_ci| paramSet | 删除密钥需要属性参数(默认传空)。 | 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci**返回:** 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci### OH_Huks_ExportPublicKeyItem() 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci``` 156e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_ExportPublicKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet, struct OH_Huks_Blob * key ) 157e41f4b71Sopenharmony_ci``` 158e41f4b71Sopenharmony_ci**描述** 159e41f4b71Sopenharmony_ci导出公钥。 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**起始版本:** 9 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**参数:** 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci| 名称 | 描述 | 166e41f4b71Sopenharmony_ci| -------- | -------- | 167e41f4b71Sopenharmony_ci| keyAlias | 待导出公钥的密钥别名,应与所用密钥生成时使用的别名相同。 | 168e41f4b71Sopenharmony_ci| paramSet | 导出公钥需要的属性参数。 | 169e41f4b71Sopenharmony_ci| key | 存放导出的公钥。 | 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**返回:** 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci### OH_Huks_FinishSession() 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci``` 179e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_FinishSession (const struct OH_Huks_Blob * handle, const struct OH_Huks_ParamSet * paramSet, const struct OH_Huks_Blob * inData, struct OH_Huks_Blob * outData ) 180e41f4b71Sopenharmony_ci``` 181e41f4b71Sopenharmony_ci**描述** 182e41f4b71Sopenharmony_ci结束密钥会话并进行相应的密钥操作,输出处理数据。 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**起始版本:** 9 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci**参数:** 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci| 名称 | 描述 | 189e41f4b71Sopenharmony_ci| -------- | -------- | 190e41f4b71Sopenharmony_ci| handle | 密钥会话句柄,通过[OH_Huks_InitSession](#oh_huks_initsession)接口生成的。 | 191e41f4b71Sopenharmony_ci| paramSet | 密钥操作对应的输入参数集。 | 192e41f4b71Sopenharmony_ci| inData | 要处理的输入数据。 | 193e41f4b71Sopenharmony_ci| outData | 经过对应的密钥操作后输出的数据。 | 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci**返回:** 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci**参见:** 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci[OH_Huks_InitSession](#oh_huks_initsession) 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci[OH_Huks_UpdateSession](#oh_huks_updatesession) 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci[OH_Huks_AbortSession](#oh_huks_abortsession) 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci### OH_Huks_GenerateKeyItem() 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci``` 211e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_GenerateKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSetIn, struct OH_Huks_ParamSet * paramSetOut ) 212e41f4b71Sopenharmony_ci``` 213e41f4b71Sopenharmony_ci**描述** 214e41f4b71Sopenharmony_ci生成密钥。 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci**起始版本:** 9 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci**参数:** 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci| 名称 | 描述 | 221e41f4b71Sopenharmony_ci| -------- | -------- | 222e41f4b71Sopenharmony_ci| keyAlias | 给要生成的密钥的别名,需要保证业务所在进程内唯一,否则会发生覆盖。 | 223e41f4b71Sopenharmony_ci| paramSetIn | 生成密钥的属性信息的参数集。 | 224e41f4b71Sopenharmony_ci| paramSetOut | 生成密钥为临时类型时,存放着密钥数据;非临时类型可为空。 | 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci**返回:** 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci### OH_Huks_GetKeyItemParamSet() 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci``` 234e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_GetKeyItemParamSet (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSetIn, struct OH_Huks_ParamSet * paramSetOut ) 235e41f4b71Sopenharmony_ci``` 236e41f4b71Sopenharmony_ci**描述** 237e41f4b71Sopenharmony_ci获取密钥的属性集。 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**起始版本:** 9 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci**参数:** 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci| 名称 | 描述 | 244e41f4b71Sopenharmony_ci| -------- | -------- | 245e41f4b71Sopenharmony_ci| keyAlias | 要获取参数集的密钥别名。 | 246e41f4b71Sopenharmony_ci| paramSetIn | 要获取参数集需要的属性TAG(默认传空)。 | 247e41f4b71Sopenharmony_ci| paramSetOut | 获取到的输出参数集。 | 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci**返回:** 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时获取成功,其他时为失败。 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci### OH_Huks_GetSdkVersion() 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci``` 257e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_GetSdkVersion (struct OH_Huks_Blob * sdkVersion) 258e41f4b71Sopenharmony_ci``` 259e41f4b71Sopenharmony_ci**描述** 260e41f4b71Sopenharmony_ci获取当前Huks sdk版本号。 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci**起始版本:** 9 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci**参数:** 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci| 名称 | 描述 | 267e41f4b71Sopenharmony_ci| -------- | -------- | 268e41f4b71Sopenharmony_ci| sdkVersion | 用于存放获取到的版本信息(字符串格式)。 | 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci**返回:** 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci### OH_Huks_ImportKeyItem() 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci``` 278e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_ImportKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet, const struct OH_Huks_Blob * key ) 279e41f4b71Sopenharmony_ci``` 280e41f4b71Sopenharmony_ci**描述** 281e41f4b71Sopenharmony_ci导入明文密钥。 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci**起始版本:** 9 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci**参数:** 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci| 名称 | 描述 | 288e41f4b71Sopenharmony_ci| -------- | -------- | 289e41f4b71Sopenharmony_ci| keyAlias | 待导入密钥的别名,需要保证业务所在进程内唯一,否则会发生覆盖。 | 290e41f4b71Sopenharmony_ci| paramSet | 待导入密钥的属性参数。 | 291e41f4b71Sopenharmony_ci| key | 待导入密钥数据,需符合Huks的格式要求,具体见[HuksTypeApi](_huks_type_api.md)。 | 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci**返回:** 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci### OH_Huks_ImportWrappedKeyItem() 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci``` 301e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_ImportWrappedKeyItem (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_Blob * wrappingKeyAlias, const struct OH_Huks_ParamSet * paramSet, const struct OH_Huks_Blob * wrappedKeyData ) 302e41f4b71Sopenharmony_ci``` 303e41f4b71Sopenharmony_ci**描述** 304e41f4b71Sopenharmony_ci导入密文密钥。 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci**起始版本:** 9 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**参数:** 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci| 名称 | 描述 | 311e41f4b71Sopenharmony_ci| -------- | -------- | 312e41f4b71Sopenharmony_ci| keyAlias | 待导入密钥的别名,需要保证业务所在进程内唯一,否则会发生覆盖。 | 313e41f4b71Sopenharmony_ci| wrappingKeyAlias | 密钥别名,该对应密钥用于密钥协商出密钥解密待导入密钥。 | 314e41f4b71Sopenharmony_ci| paramSet | 待导入加密密钥的属性参数。 | 315e41f4b71Sopenharmony_ci| wrappedKeyData | 需要导入的加密的密钥数据,需要符合Huks定义的格式,具体见[OH_Huks_AlgSuite](_huks_type_api.md#oh_huks_algsuite) | 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci**返回:** 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci### OH_Huks_InitSession() 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci``` 325e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_InitSession (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet, struct OH_Huks_Blob * handle, struct OH_Huks_Blob * token ) 326e41f4b71Sopenharmony_ci``` 327e41f4b71Sopenharmony_ci**描述** 328e41f4b71Sopenharmony_ci初始化密钥会话接口,并获取一个句柄(必选)和挑战值(可选)。 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**起始版本:** 9 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci**参数:** 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci| 名称 | 描述 | 335e41f4b71Sopenharmony_ci| -------- | -------- | 336e41f4b71Sopenharmony_ci| keyAlias | 操作的密钥的别名。 | 337e41f4b71Sopenharmony_ci| paramSet | 初始化操作的密钥参数集合。 | 338e41f4b71Sopenharmony_ci| handle | 密钥会话的句柄,后续其他操作时传入该句柄,包括[OH_Huks_UpdateSession](#oh_huks_updatesession), [OH_Huks_FinishSession](#oh_huks_finishsession), [OH_Huks_AbortSession](#oh_huks_abortsession)。 | 339e41f4b71Sopenharmony_ci| token | 存放安全访问控制时传回的token | 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci**返回:** 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci**参见:** 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci[OH_Huks_UpdateSession](#oh_huks_updatesession) 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci[OH_Huks_FinishSession](#oh_huks_finishsession) 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci[OH_Huks_AbortSession](#oh_huks_abortsession) 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci### OH_Huks_IsKeyItemExist() 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci``` 357e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_IsKeyItemExist (const struct OH_Huks_Blob * keyAlias, const struct OH_Huks_ParamSet * paramSet ) 358e41f4b71Sopenharmony_ci``` 359e41f4b71Sopenharmony_ci**描述** 360e41f4b71Sopenharmony_ci判断密钥是否存在。 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci**起始版本:** 9 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci**参数:** 365e41f4b71Sopenharmony_ci 366e41f4b71Sopenharmony_ci| 名称 | 描述 | 367e41f4b71Sopenharmony_ci| -------- | -------- | 368e41f4b71Sopenharmony_ci| keyAlias | 要查找的密钥的别名。 | 369e41f4b71Sopenharmony_ci| paramSet | 查询密钥需要的属性TAG(默认传空)。 | 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci**返回:** 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时密钥存在, 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_ERR_CODE_ITEM_NOT_EXIST](_huks_type_api.md#oh_huks_errcode)不存在,返回其他错误在其他情况。 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci### OH_Huks_ListAliases() 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci``` 381e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_ListAliases (const struct OH_Huks_ParamSet * paramSet, struct OH_Huks_KeyAliasSet ** outData ) 382e41f4b71Sopenharmony_ci``` 383e41f4b71Sopenharmony_ci**描述** 384e41f4b71Sopenharmony_ci批量查询密钥别名集。 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci**起始版本:** 12 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci**参数:** 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ci| 名称 | 描述 | 391e41f4b71Sopenharmony_ci| -------- | -------- | 392e41f4b71Sopenharmony_ci| paramSet | 查询密钥别名需要的属性TAG(默认传空)。 | 393e41f4b71Sopenharmony_ci| outData | 经过对应的查询操作后输出的密钥别名集数据。 | 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci**返回:** 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci### OH_Huks_UpdateSession() 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci``` 403e41f4b71Sopenharmony_cistruct OH_Huks_Result OH_Huks_UpdateSession (const struct OH_Huks_Blob * handle, const struct OH_Huks_ParamSet * paramSet, const struct OH_Huks_Blob * inData, struct OH_Huks_Blob * outData ) 404e41f4b71Sopenharmony_ci``` 405e41f4b71Sopenharmony_ci**描述** 406e41f4b71Sopenharmony_ci分段添加密钥操作的数据并进行相应的密钥操作,输出处理数据。 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci**起始版本:** 9 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci**参数:** 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci| 名称 | 描述 | 413e41f4b71Sopenharmony_ci| -------- | -------- | 414e41f4b71Sopenharmony_ci| handle | 密钥会话句柄,通过[OH_Huks_InitSession](#oh_huks_initsession)接口生成的。 | 415e41f4b71Sopenharmony_ci| paramSet | 密钥操作对应的输入参数集。 | 416e41f4b71Sopenharmony_ci| inData | 要处理的输入数据,如果数据过大,可分片多次调用。 | 417e41f4b71Sopenharmony_ci| outData | 经过对应的密钥操作后输出的数据。 | 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci**返回:** 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ci返回[OH_Huks_ErrCode#OH_HUKS_SUCCESS](_huks_type_api.md#oh_huks_errcode)时接口使用成功,其他时为错误。 422e41f4b71Sopenharmony_ci 423e41f4b71Sopenharmony_ci**参见:** 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ci[OH_Huks_InitSession](#oh_huks_initsession) 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci[OH_Huks_FinishSession](#oh_huks_finishsession) 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci[OH_Huks_AbortSession](#oh_huks_abortsession) 430