Huks如何导入AES的密钥?

Huks如何导入AES的密钥?

HarmonyOS
2024-06-07 09:33:32
浏览
收藏 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); 
 
}
分享
微博
QQ
微信
回复
2024-06-07 22:08:18
相关问题
huks密钥导入自定义密钥
241浏览 • 1回复 待解决
HarmonyOS HUKS 密钥证明根证书问题
439浏览 • 1回复 待解决
HUKS用户认证通过PIN生成密钥
1036浏览 • 1回复 待解决
RSA导入外部密钥实现加解密
804浏览 • 1回复 待解决
HarmonyOS Huks isKeyItemExist 报错
325浏览 • 1回复 待解决
如何使用AES ECB 加密方式?
214浏览 • 1回复 待解决
HarmonyOS动态导入是否会重复导入?
347浏览 • 1回复 待解决
Mysql中数据如何导入Greenplum?
3596浏览 • 1回复 待解决
如何进行不同规格AES加解密
843浏览 • 1回复 待解决
aes-128加密问题如何实现?
219浏览 • 1回复 待解决
鸿蒙osJS UI如何导入jquery
9443浏览 • 4回复 待解决
HarmonyOS 密钥库RSA算法使用demo
20浏览 • 1回复 待解决