如何写精华回答,获更多曝光?
发布
HarmonyOS中AES加密CBC模式中IV的实现,ArkTS和C++怎么对应上?在使用AES加密CBC模式的时候,看文档在ArkTS上采用以下的方式设置IV。对应于c层的话,HarmonyOS也提供了OH_HUKS_TAG_IV的参数,但是怎么实现以下的"IvParamsSpec"的模式了,有参考的内容吗?
function genIvParamsSpec() {
let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes
let dataIv = new Uint8Array(arr);
let ivBlob: cryptoFramework.DataBlob = { data: dataIv };
let ivParamsSpec: cryptoFramework.IvParamsSpec = {
algName: "IvParamsSpec",
iv: ivBlob
};
return ivParamsSpec;
}
async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) {
let cipher = cryptoFramework.createCipher('AES128|CBC|PKCS7');
let iv = genIvParamsSpec();
await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv);
let cipherData = await cipher.doFinal(plainText);
return cipherData;
}