VerifyMac
Verifies the hash-based message authentication code (HMAC) for a specified message, HMAC
KMS key, and MAC algorithm. To verify the HMAC, VerifyMac
computes an HMAC using
the message, HMAC KMS key, and MAC algorithm that you specify, and compares the computed HMAC
to the HMAC that you specify. If the HMACs are identical, the verification succeeds;
otherwise, it fails. Verification indicates that the message hasn't changed since the HMAC was
calculated, and the specified key was used to generate and verify the HMAC.
HMAC KMS keys and the HMAC algorithms that AWS KMS uses conform to industry standards
defined in RFC 2104
This operation is part of AWS KMS support for HMAC KMS keys. For details, see HMAC keys in AWS KMS in the AWS Key Management Service Developer Guide.
The KMS key that you use for this operation must be in a compatible key state. For details, see Key states of AWS KMS keys in the AWS Key Management Service Developer Guide.
Cross-account use: Yes. To perform this operation with a KMS key in a different AWS account, specify
the key ARN or alias ARN in the value of the KeyId
parameter.
Required permissions: kms:VerifyMac (key policy)
Related operations: GenerateMac
Eventual consistency: The AWS KMS API follows an eventual consistency model. For more information, see AWS KMS eventual consistency.
Request Syntax
{
"DryRun": boolean
,
"GrantTokens": [ "string
" ],
"KeyId": "string
",
"Mac": blob
,
"MacAlgorithm": "string
",
"Message": blob
}
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
The request accepts the following data in JSON format.
Note
In the following list, the required parameters are described first.
- KeyId
-
The KMS key that will be used in the verification.
Enter a key ID of the KMS key that was used to generate the HMAC. If you identify a different KMS key, the
VerifyMac
operation fails.Type: String
Length Constraints: Minimum length of 1. Maximum length of 2048.
Required: Yes
- Mac
-
The HMAC to verify. Enter the HMAC that was generated by the GenerateMac operation when you specified the same message, HMAC KMS key, and MAC algorithm as the values specified in this request.
Type: Base64-encoded binary data object
Length Constraints: Minimum length of 1. Maximum length of 6144.
Required: Yes
- MacAlgorithm
-
The MAC algorithm that will be used in the verification. Enter the same MAC algorithm that was used to compute the HMAC. This algorithm must be supported by the HMAC KMS key identified by the
KeyId
parameter.Type: String
Valid Values:
HMAC_SHA_224 | HMAC_SHA_256 | HMAC_SHA_384 | HMAC_SHA_512
Required: Yes
- Message
-
The message that will be used in the verification. Enter the same message that was used to generate the HMAC.
GenerateMac and
VerifyMac
do not provide special handling for message digests. If you generated an HMAC for a hash digest of a message, you must verify the HMAC for the same hash digest.Type: Base64-encoded binary data object
Length Constraints: Minimum length of 1. Maximum length of 4096.
Required: Yes
- DryRun
-
Checks if your request will succeed.
DryRun
is an optional parameter.To learn more about how to use this parameter, see Testing your permissions in the AWS Key Management Service Developer Guide.
Type: Boolean
Required: No
- GrantTokens
-
A list of grant tokens.
Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved eventual consistency. For more information, see Grant token and Using a grant token in the AWS Key Management Service Developer Guide.
Type: Array of strings
Array Members: Minimum number of 0 items. Maximum number of 10 items.
Length Constraints: Minimum length of 1. Maximum length of 8192.
Required: No
Response Syntax
{
"KeyId": "string",
"MacAlgorithm": "string",
"MacValid": boolean
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- KeyId
-
The HMAC KMS key used in the verification.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 2048.
- MacAlgorithm
-
The MAC algorithm used in the verification.
Type: String
Valid Values:
HMAC_SHA_224 | HMAC_SHA_256 | HMAC_SHA_384 | HMAC_SHA_512
- MacValid
-
A Boolean value that indicates whether the HMAC was verified. A value of
True
indicates that the HMAC (Mac
) was generated with the specifiedMessage
, HMAC KMS key (KeyID
) andMacAlgorithm.
.If the HMAC is not verified, the
VerifyMac
operation fails with aKMSInvalidMacException
exception. This exception indicates that one or more of the inputs changed since the HMAC was computed.Type: Boolean
Errors
For information about the errors that are common to all actions, see Common Errors.
- DisabledException
-
The request was rejected because the specified KMS key is not enabled.
HTTP Status Code: 400
- DryRunOperationException
-
The request was rejected because the DryRun parameter was specified.
HTTP Status Code: 400
- InvalidGrantTokenException
-
The request was rejected because the specified grant token is not valid.
HTTP Status Code: 400
- InvalidKeyUsageException
-
The request was rejected for one of the following reasons:
-
The
KeyUsage
value of the KMS key is incompatible with the API operation. -
The encryption algorithm or signing algorithm specified for the operation is incompatible with the type of key material in the KMS key
(KeySpec
).
For encrypting, decrypting, re-encrypting, and generating data keys, the
KeyUsage
must beENCRYPT_DECRYPT
. For signing and verifying messages, theKeyUsage
must beSIGN_VERIFY
. For generating and verifying message authentication codes (MACs), theKeyUsage
must beGENERATE_VERIFY_MAC
. For deriving key agreement secrets, theKeyUsage
must beKEY_AGREEMENT
. To find theKeyUsage
of a KMS key, use the DescribeKey operation.To find the encryption or signing algorithms supported for a particular KMS key, use the DescribeKey operation.
HTTP Status Code: 400
-
- KeyUnavailableException
-
The request was rejected because the specified KMS key was not available. You can retry the request.
HTTP Status Code: 500
- KMSInternalException
-
The request was rejected because an internal exception occurred. The request can be retried.
HTTP Status Code: 500
- KMSInvalidMacException
-
The request was rejected because the HMAC verification failed. HMAC verification fails when the HMAC computed by using the specified message, HMAC KMS key, and MAC algorithm does not match the HMAC specified in the request.
HTTP Status Code: 400
- KMSInvalidStateException
-
The request was rejected because the state of the specified resource is not valid for this request.
This exceptions means one of the following:
-
The key state of the KMS key is not compatible with the operation.
To find the key state, use the DescribeKey operation. For more information about which key states are compatible with each AWS KMS operation, see Key states of AWS KMS keys in the AWS Key Management Service Developer Guide .
-
For cryptographic operations on KMS keys in custom key stores, this exception represents a general failure with many possible causes. To identify the cause, see the error message that accompanies the exception.
HTTP Status Code: 400
-
- NotFoundException
-
The request was rejected because the specified entity or resource could not be found.
HTTP Status Code: 400
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: