Huks如何导入AES的密钥?

Huks如何导入AES的密钥?

HarmonyOS
2024-06-07 09:33:32
2719浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
橘猫bbt7

参考代码:

struct OH_Huks_Param GenerateKeyParam[] = { 
 
  {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, 
 
{.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, 
 
{.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT | OH_HUKS_KEY_PURPOSE_DECRYPT}, 
 
{.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PKCS7} 
 
}; 
 
//导入方法: 
 
static napi_value importKeyPair(napi_env env, napi_callback_info info) { 
  /密钥数据 keyPair/ 
  unsigned char bbb[] = {103, 85, 233, 109, 228, 13, 36, 88, 9, 60, 23, 156, 0, 181, 243, 130, 
    141, 48, 183, 122, 89, 114, 73, 56, 32, 175, 60, 182, 70, 203, 69, 205}; 
  struct OH_Huks_Blob keyPair = {32, bbb}; 
/参数配置/ 
struct OH_Huks_ParamSet testImportKeyParamSet = nullptr; 
struct OH_Huks_Result ohResult; 
/初始化参数/ 
ohResult = InitParamSet(&testImportKeyParamSet, GenerateKeyParam, 
sizeof(GenerateKeyParam) / sizeof(OH_Huks_Param)); 
if (ohResult.errorCode != OH_HUKS_SUCCESS) { 
  return nullptr; 
} 
/ 4. Import Key */ 
char newKey[] = 'test_import'; 
struct OH_Huks_Blob newKeyAlias = {.size = (uint32_t)strlen(newKey), .data = (uint8_t )newKey}; 
ohResult = OH_Huks_ImportKeyItem(&newKeyAlias, testImportKeyParamSet, &keyPair); 
 
//检验是否存在(可不要) 
 
 
ohResult = OH_Huks_IsKeyItemExist(&newKeyAlias, testImportKeyParamSet); 
if (ohResult.errorCode != OH_HUKS_SUCCESS) { 
  return nullptr; 
} 
 
OH_Huks_FreeParamSet(&testImportKeyParamSet); 
napi_value ret; 
napi_create_int32(env, ohResult.errorCode, &ret); 
 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
分享
微博
QQ
微信
回复
2024-06-07 22:08:18


相关问题
huks密钥导入自定义密钥
664浏览 • 1回复 待解决
HarmonyOS HUKS 密钥证明根证书问题
771浏览 • 1回复 待解决
HUKS用户认证通过PIN生成密钥
1337浏览 • 1回复 待解决
RSA导入外部密钥实现加解密
1204浏览 • 1回复 待解决
HarmonyOS Huks isKeyItemExist 报错
579浏览 • 1回复 待解决
HarmonyOS SM2密钥交换计算协商密钥
301浏览 • 1回复 待解决
Mysql中数据如何导入Greenplum?
3890浏览 • 1回复 待解决
HarmonyOS动态导入是否会重复导入?
624浏览 • 1回复 待解决
恭喜您,今日已阅读两篇内容,特奖励+2声望, 快来领取吧。