You need to enable JavaScript to run this app.
Key Management System

Key Management System

Copy page
Download PDF
Key management
GenerateMac - GenerateMac
Copy page
Download PDF
GenerateMac - GenerateMac

Generate a hash-based message authentication code (HMAC) for a message using HMAC KMS key and key-supported MAC algorithms

Debug

Request parameters

The following table lists only the interface-specific request parameters and some common parameters. See common parameters for more information.

const columns = [ 
  { 
    width: '20%', 
title: 'Parameter', 
    dataIndex: 'Name', 
    className: 'openapi-doc-parameter-table-name' 
  }, 
  { 
    width: 130, 
title: 'Type', 
    dataIndex: 'DataType', 
    className: 'openapi-doc-parameter-table-type' 
  }, 
  { 
    width: 90, 
title: 'Required', 
    dataIndex: 'IsRequired', 
    className: 'openapi-doc-parameter-table-required' 
  }, 
  { 
    width: '20%', 
title: 'Example Value', 
    dataIndex: 'Example', 
    className: 'openapi-doc-parameter-table-example' 
  }, 
  { 
title: 'Description', 
    dataIndex: 'Description', 
    className: 'openapi-doc-parameter-table-description' 
  }, 
]; 

const data = [ 
  { 
    rowKey: '->Action', 
    Name: 'Action', 
    DataType: 'String', 
IsRequired: 'yes', 
    Example: <RenderMd content={"GenerateMac"} />, 
Description: <RenderMd content={"The action to perform, value: GenerateMac."} />, 
    children: [ 
    ] 
  }, 
  { 
    rowKey: '->Version', 
    Name: 'Version', 
    DataType: 'String', 
IsRequired: 'Yes', 
    Example: <RenderMd content={"2021-02-18"} />, 
Description: <RenderMd content={"API version, value: 2021-02-18."} />, 
    children: [ 
    ] 
  }, 
  { 
    rowKey: '->KeyringName', 
    Name: 'KeyringName', 
    DataType: 'String', 
IsRequired: 'No', 
    Example: <RenderMd content={"keyringName"} />, 
Description: <RenderMd content={"Keyring name, length 2 - 31 characters. Valid characters: [a-zA-Z0-9-_]"} />, 
    children: [ 
    ] 
  }, 
  { 
    rowKey: '->KeyName', 
    Name: 'KeyName', 
    DataType: 'String', 
IsRequired: 'No', 
    Example: <RenderMd content={"keyName"} />, 
Description: <RenderMd content={"Primary key name, length between 2 and 31 characters. Allowed characters: [a-zA-Z0-9-_]"} />, 
    children: [ 
    ] 
  }, 
  { 
    rowKey: '->KeyID', 
    Name: 'KeyID', 
    DataType: 'String', 
IsRequired: 'No', 
    Example: <RenderMd content={"0324d9b3-c5d9-4b6f-94e7-884010a16fee"} />, 
Description: <RenderMd content={"Primary key ID, choose one: \nKeyringName and KeyName\nKeyID"} />, 
    children: [ 
    ] 
  }, 
  { 
    rowKey: '->Message', 
    Name: 'Message', 
    DataType: 'String', 
IsRequired: 'Yes' 
    Example: <RenderMd content={"testMessage"} />, 
Description: <RenderMd content={"Signature message.\nWhen MessageType is RAW: if raw signature data is specified, the hash algorithm in Algorithm will generate a digest from the raw message before signing; valid length: [1, 4096]\nWhen MessageType is DIGEST: the maximum length is 32 bytes"} /> 
    children: [ 
    ] 
  }, 
  { 
    rowKey: '->MacAlgorithm', 
    Name: 'MacAlgorithm', 
    DataType: 'String', 
IsRequired: 'yes', 
    Example: <RenderMd content={"HMAC_SHA_256"} />, 
Description: <RenderMd content={"MacAlgorithm algorithm, supports only HMAC_SM3|HMAC_SHA_256"} />, 
    children: [ 
    ] 
  }, 

]; 

return (<Table 
  rowKey="rowKey" 
  className="openapi-doc-parameter-table" 
  columns={columns} 
  data={data} 
  border={ { cell: true, wrapper: true } } 
  scroll={ { x: "auto" } } 
  pagination={false} 
/>);

response parameters

The following table lists only the unique response parameters for this interface. For more information, see response structure.

const columns = [ 
  { 
    width: '25%', 
title: 'Parameter', 
    dataIndex: 'Name', 
    className: 'openapi-doc-parameter-table-name', 
  }, 
  { 
    width: 130, 
title: 'Type', 
    dataIndex: 'DataType', 
    className: 'openapi-doc-parameter-table-type' 
  }, 
  { 
    width: '25%', 
title: 'Example value', 
    dataIndex: 'Example', 
    className: 'openapi-doc-parameter-table-example' 
  }, 
  { 
title: 'Description', 
    dataIndex: 'Description', 
    className: 'openapi-doc-parameter-table-description' 
  }, 
]; 

const data = [ 
  { 
    rowKey: "->KeyID", 
    Name: "KeyID", 
    DataType: "String", 
    Example: <RenderMd content={"41cb6fdba8ef249312e4ce66f7d6b5b68e565ef84d6333793b5934d6779e847c"} />, 
Description: <RenderMd content={"unique identifier of the master key in UUID format"} /> 
    children: [ 
    ] 
  }, 
  { 
    rowKey: "->Mac", 
    Name: "Mac", 
    DataType: "String", 
    Example: <RenderMd content={"0324d9b3-c5d9-4b6f-94e7-884010a16fee"} />, 
    Description: <RenderMd content={"message authentication code"} />, 
    children: [ 
    ] 
  }, 
]; 

return (<Table 
  rowKey="rowKey" 
  className="openapi-doc-parameter-table" 
  columns={columns} 
  data={data} 
  border={ { cell: true, wrapper: true } } 
  scroll={ { x: "auto" } } 
  pagination={false} 
/>);

Request example

POST /?Action=GenerateMac&Version=2021-02-18 HTTP/1.1 
Host: kms.cn-beijing.volcengineapi.com 
Content-Type: application/json; charset=UTF-8 
X-Date: 20240708T151941Z 
X-Content-Sha256: 287e874e******d653b44d21e 
Authorization: HMAC-SHA256 Credential=Adfks******wekfwe/20240708/cn-beijing/kms/request, SignedHeaders=host;x-content-sha256;x-date, Signature=47a7d934ff7b37c03938******cd7b8278a40a1057690c401e92246a0e41085f 

{ 
  "Message": "5Lq65LmL5Yid5oCn5pys5ZaE5oCn55u46L+R5Lmg55u46L+c", 
  "MacAlgorithm": "HMAC_SHA_256", 
  "KeyringName": "fd65f1d1-9b0c-4254-897f-1965b2", 
  "KeyName": "bbbb" 
}

Example response

{ 
  "ResponseMetadata": { 
    "RequestId": "02172956002604000000000000000000000ffff0a7ab9adc81d5f", 
    "Action": "GenerateMac", 
    "Version": "2021-02-18", 
    "Service": "kms", 
    "Region": "cn-beijing" 
  }, 
  "Result": { 
    "KeyID": "1096b6a5-3bb5-430a-8c5b-65ae1ca73346", 
    "Mac": "49NIoYbYAkVv8tT6hoAY+jJ0gZCRQujiv7wc0S763ao=" 
  } 
}

Error code

The table below lists error codes related to this interface and business logic. Refer to the Common Error Codes documentation for public error codes.

Status Code
Error Code
Error Message
Description
400
MissingParameter

The request is missing %s parameter.

400
InvalidParameter

The request parameter %s is invalid.

400
InvalidKeyStatus

Current key status: %s does not allow to perform this action

400
InvalidKeyUsage

Current key usage only allows: %s. Please use different keys for encryption/decryption and signing/verification.

403
AccessDenied

User is not authorized to do this action

403
Reject.Throttling.CMK

The request of CMK: %s upper limit is exceeded.

404
Not Found

Not found %s [%s].

500
UndefinedError

Undefined Internal Error. Pls Contact With Admin.

Last updated: 2025.06.27 15:24:17