目录

Generating Secure Random Numbers (ArkTS)

Starting from API version 12, lightweight smart wearable devices support operations related to obtaining random numbers.

Random numbers are used to generate temporary session keys and asymmetric encryption algorithm keys. In encryption and decryption, a secure random number generator must feature randomness, unrepeatability, and unpredictability. The random numbers generated by the system meet the requirements of cryptography security pseudo-randomness.

You can call APIs to:

It will be helpful if you have basic knowledge of encryption and decryption and understand the following basic concepts:

Supported Algorithms and Specifications

The random number generation algorithm uses the RAND_priv_bytes interface of OpenSSL to generate secure random numbers.

Algorithm Length (Byte)
CTR_DRBG [1, INT_MAX]

How to Develop

  1. Call cryptoFramework.createRandom to create a Random instance.

  2. (Optional) Call Random.setSeed to set a seed for the random number generation pool.

  3. Call Random.generateRandom or Random.generateRandomSync to generate a secure random number.

    The length of the random number to generate ranges from 1 to INT_MAX, in bytes.