• Key Management Service

kms
  1. Help Center
  2. Key Management Service
  3. API Reference
  4. APIs
  5. Creating a Random Number

Creating a Random Number

Function

This API allows you to obtain a random number whose length can be up to 512 bits.

URI

  • URI format

    POST /v1.0/{project_id}/kms/gen-random

  • Parameter description

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Project ID

Requests

Request parameters

Parameter

Type

Mandatory

Description

random_data_length

String

Yes

Number of bits of a random number. The value is 512.

sequence

String

No

36-byte serial number of a request message

Example: 919c82d4-8046-4722-9094-35c3c6524cff

Responses

Response parameters

Parameter

Type

Mandatory

Description

random_data

String

Yes

Random numbers are expressed in hexadecimal format. Two characters indicate one byte. Length of a random number must be consistent with the random_data_length value entered by a user.

Examples

The following example describes how to create a random number with the length of 512 bits.

  • Example request
    {
        "random_data_length": "512"
    }
  • Example response
    {
        "random_data": "5791C223E87124AB9FC29B5A8AC60BE4B98D168F47A58BB2A88833E40D6ED32D57E2AAB5410492EB25096873F9CE3D45E0D22F820A5AB4EEADC33A1A6AE780F1"
    }

    or

    {
        "error": {
            "error_code": "KMS.XXXX",
            "error_msg": "XXX"
        }
    }

Status Codes

Table 1 lists the normal status code returned by the response.
Table 1 Status codes

Status Code

Status

Description

200

OK

Request processed successfully.

Exception status code. For details, see Status Codes.