generateMac method
Generates a Message Authentication Code (MAC) cryptogram within Amazon Web Services Payment Cryptography.
You can use this operation to authenticate card-related data by using known data values to generate MAC for data validation between the sending and receiving parties. This operation uses message data, a secret encryption key and MAC algorithm to generate a unique MAC value for transmission. The receiving party of the MAC must use the same message data, secret encryption key and MAC algorithm to reproduce another MAC value for comparision.
You can use this operation to generate a DUPKT, CMAC, HMAC or EMV MAC by
setting generation attributes and algorithm to the associated values. The
MAC generation encryption key must have valid values for
KeyUsage such as TR31_M7_HMAC_KEY for HMAC
generation, and the key must have KeyModesOfUse set to
Generate.
For information about valid keys for this operation, see Understanding key attributes and Key types for specific data operations in the Amazon Web Services Payment Cryptography User Guide.
Cross-account use: This operation supports cross-account use when the key has a resource-based policy that grants access. For more information, see Resource-based policies.
Related operations:
May throw AccessDeniedException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ThrottlingException.
May throw ValidationException.
Parameter generationAttributes :
The attributes and data values to use for MAC generation within Amazon Web
Services Payment Cryptography.
Parameter keyIdentifier :
The keyARN of the MAC generation encryption key.
Parameter messageData :
The data for which a MAC is under generation. This value must be
hexBinary.
Parameter macLength :
The length of a MAC under generation.
Implementation
Future<GenerateMacOutput> generateMac({
required MacAttributes generationAttributes,
required String keyIdentifier,
required String messageData,
int? macLength,
}) async {
_s.validateNumRange(
'macLength',
macLength,
4,
32,
);
final $payload = <String, dynamic>{
'GenerationAttributes': generationAttributes,
'KeyIdentifier': keyIdentifier,
'MessageData': messageData,
if (macLength != null) 'MacLength': macLength,
};
final response = await _protocol.send(
payload: $payload,
method: 'POST',
requestUri: '/mac/generate',
exceptionFnMap: _exceptionFns,
);
return GenerateMacOutput.fromJson(response);
}