Updated on 2025-09-15 GMT+08:00

Verifying a MAC

Function

This API is used to verify a MAC.

Constraints

  • This API is supported only for keys whose key_usage is GENERATE_VERIFY_MAC.

Calling Method

For details, see Calling APIs.

URI

POST /v1.0/{project_id}/kms/verify-mac

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token. It can be obtained by calling the IAM API. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

key_id

Yes

String

Key ID

mac_algorithm

Yes

String

MAC algorithm. HMAC_SM3 is supported only in China. Possible values are as follows:

  • HMAC_SHA_256

  • HMAC_SHA_384

  • HMAC_SHA_512

  • HMAC_SM3

message

Yes

String

Message to be processed. The original message can contain 1 to 4,096 characters. Convert the original message to the Base64 format and import it.

mac

Yes

String

MAC to be verified

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

key_id

String

Key ID

mac_algorithm

String

MAC algorithm

mac_valid

Boolean

MAC verification result

Example Requests

{
  "key_id" : "826314dd-1b5b-4037-b976-5f9b7a17df46",
  "mac_algorithm" : "HMAC_SHA_256",
  "message" : "ZmRzYQ==",
  "mac" : "8549f9f5ef335184e23e6d477776f0fd338d02c59e48e52e8d81d158e2fc9262"
}

Example Responses

Status code: 200

Request succeeded.

{
  "mac_algorithm" : "HMAC_SHA_256",
  "key_id" : "826314dd-1b5b-4037-b976-5f9b7a17df46",
  "mac_valid" : false
}

Status Codes

Status Code

Description

200

Request succeeded.

Error Codes

See Error Codes.