harmony 鸿蒙Basic Security Capability Development

  • 2023-06-24
  • 浏览 (478)

Basic Security Capability Development

What is the maximum number of bytes that can be encrypted at a time in AES GCM mode in HUKS?

Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)

Solution

In HUKS, a maximum of 64 bytes can be encrypted at a time in AES GCM mode.

Example

/* Encrypt the key. */
await huks.init(srcKeyAlias, encryptOptions).then((data) => {
 console.info(`test init data: ${JSON.stringify(data)}`);
 handle = data.handle;
}).catch((err) => {
 console.info('test init err information: ' + JSON.stringify(err));
});
encryptOptions.inData = aesCipherStringToUint8Array(cipherInData.slice (0,64)); // Take 64 bytes.
await huks.update(handle, encryptOptions).then(async (data) => {
 console.info(`test update data ${JSON.stringify(data)}`);
 encryptUpdateResult = Array.from(data.outData);
}).catch((err) => {
 console.info('test update err information: ' + err);
});
encryptOptions.inData = aesCipherStringToUint8Array(cipherInData.slice (64,80)); // Remaining data

What if garbled characters are returned by digest() of Md in Crypto framework?

Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)

Symptom

In the CryptoFramework, garbled characters are returned by digest() of Md.

Solution

The DataBlob returned by digest() is of the Uint8Array type and needs to be converted into a hexadecimal string before being printed. You can use the online MD5 encryption tool to verify the result.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙FAQs

harmony 鸿蒙Using NDK in a CMake Project

harmony 鸿蒙Application Access Control Development

harmony 鸿蒙Application Model Development

harmony 鸿蒙ArkUI Animation/Interaction Event Development (ArkTS)

harmony 鸿蒙ArkTS Syntax Usage

harmony 鸿蒙ArkUI Component Development (ArkTS)

harmony 鸿蒙ArkUI Development (JS)

harmony 鸿蒙ArkUI Layout Development (ArkTS)

harmony 鸿蒙ArkUI Routing/Navigation Development (ArkTS)

0  赞