HarmonyOSuserid 0 进程调用huks加解密时失败
// 生成密钥
export async function GenerateAesKey(keyAlias:string):Promise<boolean> {
let status = await CheckKey(keyAlias);
LBSLog.i(TAG, `CheckKey status: ${status}`);
if (status) {
return true;
}
let genProperties = GetAesGenerateProperties();
let options: huks.HuksOptions = {
properties: genProperties
}
await huks.generateKeyItem(keyAlias, options)
.then((data) => {
LBSLog.i(TAG, `promise: generate AES Key success`);
}).catch((error: Error) => {
LBSLog.e(TAG, `promise: generate AES Key failed, ${JSON.stringify(error)}`);
return false;
})
return true;
}
// 加密
export async function EncryptData(keyAlias:string, text:string):Promise<Uint8Array|undefined> {
let status = await GenerateAesKey(keyAlias)
if (!status) {
return undefined;
}
let encryptProperties = GetAesEncryptProperties();
let options: huks.HuksOptions = {
properties: encryptProperties,
inData: stringToUint8Array(text)
}
await huks.initSession(keyAlias, options)
.then((data) => {
handle = data.handle;
}).catch((error: Error) => {
LBSLog.e(TAG, `promise: init EncryptData failed, ${JSON.stringify(error)}`);
return undefined;
})
let cipherText:Uint8Array|undefined = undefined;
await huks.finishSession(handle, options)
.then((data) => {
cipherText = data.outData;
}).catch((error: Error) => {
LBSLog.e(TAG, `promise: encrypt data failed, ${JSON.stringify(error)}`);
return undefined;
})
return cipherText;
}
// 解密
export async function DecryptData(keyAlias:string, cipherText:Uint8Array):Promise<string|undefined> {
let status = await CheckKey(keyAlias);
if (!status) {
return undefined;
}
let decryptOptions = GetAesDecryptProperties()
let options: huks.HuksOptions = {
properties: decryptOptions,
inData: cipherText
}
await huks.initSession(keyAlias, options)
.then((data) => {
handle = data.handle;
}).catch((error: Error) => {
LBSLog.e(TAG, `promise: init DecryptData failed, ${JSON.stringify(error)}`);
return undefined;
})
let text:string|undefined = undefined;
await huks.finishSession(handle, options)
.then((data) => {
text = Uint8ArrayToString(data.outData as Uint8Array);
}).catch((error: Error) => {
LBSLog.e(TAG, `promise: decrypt data failed, ${JSON.stringify(error)}`);
return undefined;
})
return text;
}
行 34615: 08-16 15:06:51.924 844 910 E C02F06/huks_service/HUKS: [a92abbfa8be1781 0 0]CheckIfOnlyStorageLevelTagExist[375]: invalid userId when tag storage level is CE or ECE, userId is 0
行 34616: 08-16 15:06:51.924 844 910 E C02F06/huks_service/HUKS: [a92abbfa8be1781 0 0]HksConstructStoreFileInfo[280]: check storagelevel or specificuserid tag failed, ret = -3.
行 34617: 08-16 15:06:51.924 844 910 E C02F06/huks_service/HUKS: [a92abbfa8be1781 0 0]HksManageStoreDeleteKeyBlob[340]: hks construct store file info failed, ret = -3.
行 34618: 08-16 15:06:51.924 844 910 E C02F06/huks_service/HUKS: [a92abbfa8be1781 0 0]HksServiceDeleteKey[1179]: service delete main key failed, ret = -3
行 34619: 08-16 15:06:51.924 844 910 E C02F06/huks_service/HUKS: [a92abbfa8be1781 0 0]CheckKeyCondition[425]: delete keyblob from storage failed, ret = -3
行 34621: 08-16 15:06:51.924 844 910 E C02F06/huks_service/HUKS: [a92abbfa8be1781 0 0]HksServiceGenerateKey[962]: check key condition failed, ret = -3
行 34622: 08-16 15:06:51.924 844 910 I C02D33/huks_service/HiTraceC: [a92abbfa8be1781 0 0]HiTraceEnd.
行 34627: 08-16 15:06:51.924 844 910 E C02F06/huks_service/HUKS: HksIpcServiceGenerateKey[106]: HksServiceGenerateKey fail, ret = -3
行 34628: 08-16 15:06:51.925 844 910 I C02F06/huks_service/HUKS: OnRemoteRequest[398]: finish code:0, total cost 2 ms, sessionId = 497
行 34633: 08-16 15:06:51.925 10380 10395 E C02F06/com.huawei.hmos.location:core/HUKS: HksClientGenerateKey[121]: HksSendRequest fail, ret = -3
行 34649: 08-16 15:06:51.926 10380 10408 E A02300/com.huawei.hmos.location:core/L_AesHuks: promise: generate AES Key failed, {"code":401,"message":["Invalid parameters."],"data":null}
userid 0 进程调用huks加解密时失败
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HUKS的RSA加解密,关于RSA加解密的代码示例
1041浏览 • 1回复 待解决
如何使用HUKS处理超过100k的明文数据加解密
677浏览 • 1回复 待解决
HUKS对于超过100k的明文数据加解密的处理
710浏览 • 1回复 待解决
HarmonyOS 3des加解密失败
26浏览 • 1回复 待解决
HUKS的SM4加解密,判断密钥的存在以及删除密钥
979浏览 • 1回复 待解决
使用AES对称密钥(CBC模式)加解密,生成symKey失败
330浏览 • 1回复 待解决
HarmonyOS的md5加解密 rsa加解密 md5加解密等有公共方法么?
796浏览 • 1回复 待解决
HarmonyOS 加解密问题
52浏览 • 1回复 待解决
HarmonyOS AES加解密问题
47浏览 • 1回复 待解决
HarmonyOS AES加解密咨询
94浏览 • 1回复 待解决
HarmonyOS 加解密 demo
534浏览 • 1回复 待解决
HarmonyOS 加解密咨询
39浏览 • 1回复 待解决
HUKS解密时,明文包含中文字符,解密后明文与原明文不一致
2092浏览 • 1回复 待解决
多种加密方式实现加解密
1081浏览 • 1回复 待解决
HarmonyOS 加解密算法如何使用
66浏览 • 1回复 待解决
加解密算法库框架使用
902浏览 • 1回复 待解决
HarmonyOS 加解密算法匹配
77浏览 • 1回复 待解决
des解密同步方法解密失败
236浏览 • 1回复 待解决
Cipher DES加解密,使用cryptoFramework.createCipher无法实现DES加解密,如何实现?
236浏览 • 1回复 待解决
HUKS解密时,若明文包含中文字符,则解密后明文与原明文不一致
2267浏览 • 1回复 待解决
RSA导入外部密钥实现加解密
837浏览 • 1回复 待解决
加解密问题的定位指导
392浏览 • 1回复 待解决
HarmonyOS DEC加解密的支持
51浏览 • 1回复 待解决
huks sm2签名验签失败
259浏览 • 1回复 待解决
HarmonyOS NAPI层中,huks加解密并没有返回 加密后密文的长度和解密后明文的长度,示例代码中是定值
41浏览 • 1回复 待解决
报错显示参数错误,即加密的时候加密属性数据有误,官方文档中有对应的AES加解密的写法
请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/huks-encryption-decryption-arkts-V5#%E5%BC%80%E5%8F%91%E6%AD%A5%E9%AA%A4