Skip to main content

GenerateMAC

Generates a message authentication code (MAC) for a message using a KMS key.

Description

The `GenerateMAC` operation uses the specified KMS key and MAC algorithm to generate a message authentication code (MAC). A MAC is a cryptographic value that helps ensure data integrity and authenticity.

note
  • The KMS key must have a `KeyUsage` value of `GENERATE_VERIFY_MAC`.
  • The maximum message size is 4096 bytes.
  • To verify the MAC, use the `VerifyMAC` operation.

Request Syntax

POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.GenerateMAC
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "Message": "SGVsbG8gV29ybGQ=", "MacAlgorithm": "HMAC_SHA_256" }
Values in italics indicate user input and should be replaced with actual values.

Request Parameters

Headers

NameDescriptionRequiredType
Content-TypeMust be "application/x-amz-json-1.1"Yesstring
X-Amz-TargetMust be "TrentService.GenerateMAC"Yesstring

Request Body

NameDescriptionRequiredType
KeyIdSpecifies the KMS key to use for MAC generation. The KMS key must have a KeyUsage of GENERATE_VERIFY_MAC.Yesstring
MessageThe message to be authenticated. The message can contain up to 4096 bytes.Yesblob
MacAlgorithmThe MAC algorithm to use. Valid values are HMAC_SHA_224, HMAC_SHA_256, HMAC_SHA_384, or HMAC_SHA_512.Yesstring
GrantTokensA list of grant tokens. Use grant tokens when your permission to call this operation comes from a new grant that has not yet achieved eventual consistency.Noarray

Examples

Example 1: Generate a MAC using HMAC-SHA-256

POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.GenerateMAC
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "Message": "SGVsbG8gV29ybGQ=", "MacAlgorithm": "HMAC_SHA_256" }
Values in italics indicate user input and should be replaced with actual values.
HTTP/1.1 200 OK
Content-Type: application/x-amz-json-1.1
{ "KeyId": "arn:verenc:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "MAC": "Base64-encoded MAC value", "MacAlgorithm": "HMAC_SHA_256" }
Values in italics indicate variable response values.

Example 2: Generate a MAC using HMAC-SHA-512

POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.GenerateMAC
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "Message": "SGVsbG8gV29ybGQ=", "MacAlgorithm": "HMAC_SHA_512" }
Values in italics indicate user input and should be replaced with actual values.
HTTP/1.1 200 OK
Content-Type: application/x-amz-json-1.1
{ "KeyId": "arn:verenc:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "MAC": "Base64-encoded MAC value", "MacAlgorithm": "HMAC_SHA_512" }
Values in italics indicate variable response values.

Response Syntax

HTTP/1.1 200 OK
Content-Type: application/x-amz-json-1.1
{ "KeyId": "string", "MAC": "blob", "MacAlgorithm": "string" }
Values in italics indicate variable response values.

Response Elements

NameDescriptionRequiredType
KeyIdThe Amazon Resource Name (ARN) of the KMS key used to generate the MAC.NoString
MACThe generated MAC in base64-encoded format.NoString
MacAlgorithmThe MAC algorithm that was used to generate the MAC.NoString

Special Errors

Error CodeDescription
DependencyTimeoutExceptionThe system timed out while trying to fulfill the request.
DisabledExceptionThe request was rejected because the specified KMS key is disabled.
InvalidKeyUsageExceptionThe request was rejected because the specified KeyId value cannot be used for this operation.
KeyUnavailableExceptionThe request was rejected because the specified KMS key was not available.
KMSInternalExceptionThe request was rejected because an internal error occurred.
KMSInvalidStateExceptionThe request was rejected because the key state is not valid for this operation.
NotFoundExceptionThe request was rejected because the specified entity or resource could not be found.

Permissions

To use the `GenerateMAC` operation, you must have the following permissions:

  • `kms:GenerateMAC` on the KMS key (specified in the policy)

Try It Out

Test GenerateMAC

Generate a message authentication code (MAC) for a message.

Coming Soon

This feature is currently under development and will be available soon.