Native层回传的公钥数据应用于ets文件导致崩溃

Native层采用 
ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, generateKeyParamSet, nullptr); 
ohResult = OH_Huks_ExportPublicKeyItem(&aliasBlob, generateKeyParamSet, &publicKey); 
生成并导出RSA2048公钥294字节。 
但在ets层采用 
let pkBlob: cryptoFramework.DataBlob = { data : resultTemp.data }; 
let rsaGenerator: cryptoFramework.AsyKeyGenerator = cryptoFramework.createAsyKeyGenerator(“RSA2048”); 
rsaGenerator.convertKey(pkBlob, null, (err, keyPair) => { 
  if (err) { 
    AlertDialog.show({ message: ‘Convert keyPair fail’ }); 
    return; 
  } 
}) 
构造公私钥对用于加密时app崩溃。 
错误信息如下: 
01-31 18:05:55.833 28011-28011 C02F10/[HCF] com.examp…siondemo E GetBlobFromNapiUint8Arr: failed to get valid rawData. 
01-31 18:05:55.833 28011-28011 C02F10/[HCF] com.examp…siondemo E GetPkAndSkBlobFromNapiValueIfInput: failed to get pubKey. 
01-31 18:05:55.835 28011-28011 C02F10/[HCF] com.examp…siondemo E JsConvertKey: build context fail. 
01-31 18:05:55.835 28011-28011 C03F00/ArkCompiler com.examp…siondemo E [ecmascript] pending exception before jsnapi interface called, which is IsMixedDebugEnabled in line: 532 
01-31 18:05:55.835 28011-28011 C03F00/ArkCompiler com.examp…siondemo E [ecmascript] print exception info: 
01-31 18:05:55.835 28011-28011 C03F00/ArkCompiler com.examp…siondemo E Error: build context fail. 
01-31 18:05:55.835 28011-28011 C03F00/ArkCompiler com.examp…siondemo E at anonymous (esealshield/src/main/ets/pages/StringBoolType.ets:292:17) 
01-31 18:05:55.835 28011-28011 C03F00/ArkCompiler com.examp…siondemo E [default] Call:1819 occur exception need return 
01-31 18:05:55.835 28011-28011 C03F00/ArkCompiler com.examp…siondemo E [ecmascript] pending exception before jsnapi interface called, which is ExecutePendingJob in line: 758 
01-31 18:05:55.835 28011-28011 C03F00/ArkCompiler com.examp…siondemo E [ecmascript] print exception info: 
01-31 18:05:55.835 28011-28011 C03F00/ArkCompiler com.examp…siondemo E Error: build context fail. 
01-31 18:05:55.835 28011-28011 C03F00/ArkCompiler com.examp…siondemo E at anonymous (esealshield/src/main/ets/pages/StringBoolType.ets:292:17) 
01-31 18:05:55.835 28011-28011 C01300/JsEnv com.examp…siondemo E [uncaught_exception_callback.cpp(GetNativeStrFromJsTaggedObj:36)]Failed to convert value from key. 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E [main_thread.cpp(operator():1360)] 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E com.example.dataconversiondemo is about to exit due to RuntimeError 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E Error type:Error 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E Error message:build context fail. 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E Error code: 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E SourceCode: 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E rsaGenerator.convertKey(pkBlob, null, (err, keyPair) => { 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E ^ 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E Stacktrace: 
01-31 18:05:55.851 28011-28011 C01305/Appkit com.examp…siondemo E at anonymous (esealshield/src/main/ets/pages/StringBoolType.ets:183:13)
HarmonyOS
2024-05-08 22:50:34
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
快乐小肥仔

rsaGenerator.convertKey 入参规定入参必须是 Uint8Array类型,代码需要修改下:

let pkBlob: cryptoFramework.DataBlob = { data : resultTemp.data };---->let pkBlob: cryptoFramework.DataBlob = { data : new Uint8Array(resultTemp.data) };
分享
微博
QQ
微信
回复
2024-05-09 12:07:34
相关问题
如何使用RSA加密明文数据
465浏览 • 1回复 待解决
HarmonyOS RSA如何用解密
623浏览 • 0回复 待解决
HarmonyOS 支持rsa使用解密吗
483浏览 • 1回复 待解决
rsa 解密初始化报错
277浏览 • 1回复 待解决
HarmonyOS Native获取应用路径方式
388浏览 • 1回复 待解决
如何实现RSAPK加密一段文字
613浏览 • 1回复 待解决
native如何访问rawfile二进制文件
1937浏览 • 1回复 待解决