HarmonyOS 鸿蒙Next 上传图片导致包错崩溃,签名已使用分段签名
HarmonyOS 鸿蒙Next 上传图片导致包错崩溃,签名已使用分段签名
上传图片,导致包错,然后崩溃,我们签名也确实用了分段签名
3 回复
参考这个写法:
key = "secret key 1234"
let encrypted: string = CryptoJS.TripleDES.encrypt('hello world', key,{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
}).toString();
let decrypted: string = CryptoJS.TripleDES.decrypt(encrypted.toString(), key,{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
}).toString(CryptoJS.enc.Utf8)
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
参考这份代码:
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
import { buffer, util } from '@kit.ArkTS';
[@Entry](/user/Entry)
[@Component](/user/Component)
struct EncryptMessageDemo {
[@State](/user/State) message: string = 'Hello World';
build() {
Column() {
Text(this.message)
.id('EncryptMessageDemoHelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
Button('加解密')
.onClick(() => {
main()
})
}
.height('100%')
.width('100%')
}
}
// 加密消息
function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) {
let cipher = cryptoFramework.createCipher('3DES192|ECB|PKCS7');
cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null);
let encryptData = cipher.doFinalSync(plainText);
return encryptData;
}// 解密消息
function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) {
let decoder = cryptoFramework.createCipher('3DES192|ECB|PKCS7');
decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null);
let decryptData = decoder.doFinalSync(cipherText);
return decryptData;
}
async function genSymKeyByData(symKeyData: Uint8Array) {
let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData };
let symGenerator = cryptoFramework.createSymKeyGenerator('3DES192');
let symKey = await symGenerator.convertKey(symKeyBlob);
console.info('convertKey success');
return symKey;
}
async function main() {
let ketstr = '的密钥'
let base64Helper = new util.Base64Helper();
let data = base64Helper.decodeSync(ketstr)
let symKey = await genSymKeyByData(data);
let unit8arratData = getContext().resourceManager.getRawFileContentSync("demo.jpg");
let plainText: cryptoFramework.DataBlob = { data: unit8arratData };
let encryptText = encryptMessage(symKey, plainText);
let decryptText = decryptMessage(symKey, encryptText);
if (plainText.data.toString() === decryptText.data.toString()) {
console.info('decrypt ok');
console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8'));
} else {
console.error('decrypt failed');
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
更多关于HarmonyOS 鸿蒙Next 上传图片导致包错崩溃,签名已使用分段签名的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
1
针对HarmonyOS 鸿蒙Next上传图片导致包错崩溃,且签名已使用分段签名的问题,可能的原因及解决方案如下:
- 权限问题:确保应用已正确声明并请求了读取存储权限,以及网络权限(如需上传至网络)。在鸿蒙系统中,权限管理较为严格,未获取相应权限可能导致上传失败并崩溃。
- 文件路径问题:检查上传的图片路径是否正确。鸿蒙系统的文件系统可能与Android或iOS有所不同,需确保路径格式与鸿蒙系统兼容。
- 组件配置:如果使用特定的上传组件,请确保已按照官方文档正确配置。配置错误可能导致上传功能异常。
- 签名验证:尽管已使用分段签名,但仍需检查签名证书是否有效,签名密码是否输入正确,以及签名配置文件中的信息是否与证书一致。
如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html 。