目录

Generating an MD Using SHA-256 (ArkTS)

For details about the algorithm specifications, see Supported Algorithms and Specifications.

Starting from API version 12, lightweight smart wearable devices support message digest computation and operations.

How to Develop

During the MD operation, you can pass in all the data at a time or pass in data by segment. For the same piece of data, the result will be the same no matter how the data is passed. Use the appropriate method based on the data size.

The following provides examples of MD operations with different data passing methods.

[h2]Generating an MD by Passing In Full Data

  1. Call cryptoFramework.createMd with the MD algorithm SHA256 to create a message digest (Md) instance.

  2. Call Md.update to pass in the full data. The data to be passed in by a single update() operation is not size bound.

  3. Call Md.digest to generate an MD.

  4. Call Md.getMdLength to obtain the MD length, in bytes.

[h2]Generating an MD by Passing In Data by Segment

  1. Call cryptoFramework.createMd with the MD algorithm SHA256 to create a message digest (Md) instance.

  2. Call Md.update multiple times to pass in 20 bytes each time.

  3. Call Md.digest to generate an MD.

  4. Call Md.getMdLength to obtain the MD length, in bytes.