Skip to main content

VerifyMac

Verifies the integrity and authenticity of a message using a message authentication code (MAC).

Description

The `VerifyMac` operation uses a KMS key to verify a message authentication code (MAC). This operation is the complement of the `GenerateMAC` operation. If the MAC is valid, the `VerifyMac` operation returns a `MacValid` value of `true`. If the MAC is not valid, the operation returns a `MacValid` value of `false`.

note
  • The KMS key must have a `KeyUsage` value of `GENERATE_VERIFY_MAC`.
  • The maximum message size is 4096 bytes.
  • The MAC algorithm must match the one used in the GenerateMAC request.

Request Syntax

POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.VerifyMac
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "Message": "SGVsbG8gV29ybGQ=", "MacAlgorithm": "HMAC_SHA_256", "Mac": "Base64-encoded MAC value" }
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.VerifyMac"Yesstring

Request Body

NameDescriptionRequiredType
KeyIdIdentifies the KMS key that will be used to verify the MAC. This must be the ID or ARN of a KMS key with a KeyUsage of GENERATE_VERIFY_MAC.Yesstring
MessageThe message that was used to generate the MAC. The message can be up to 4096 bytes.Yesblob
MacAlgorithmThe MAC algorithm that was used to generate the MAC. Valid values are HMAC_SHA_224, HMAC_SHA_256, HMAC_SHA_384, or HMAC_SHA_512.Yesstring
MacThe MAC to verify. This is the value of the MAC field that was returned by the GenerateMAC operation.Yesblob
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: Verify a MAC using HMAC-SHA-256

POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.VerifyMac
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "Message": "SGVsbG8gV29ybGQ=", "MacAlgorithm": "HMAC_SHA_256", "Mac": "Base64-encoded MAC value" }
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", "MacValid": true, "MacAlgorithm": "HMAC_SHA_256" }
Values in italics indicate variable response values.

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

POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.VerifyMac
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "Message": "SGVsbG8gV29ybGQ=", "MacAlgorithm": "HMAC_SHA_512", "Mac": "Base64-encoded MAC value" }
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", "MacValid": true, "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", "MacValid": "boolean", "MacAlgorithm": "string" }
Values in italics indicate variable response values.

Response Elements

NameDescriptionRequiredType
KeyIdThe Amazon Resource Name (ARN) of the KMS key that was used to verify the MAC.NoString
MacValidA Boolean value that indicates whether the MAC is valid.NoString
MacAlgorithmThe MAC algorithm that was used to verify 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.
MacInvalidExceptionThe request was rejected because the MAC verification failed.

Permissions

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

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

Try It Out

Test VerifyMac

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

Coming Soon

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