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:
Parameters:
-
key_identifier
(KeyArnOrKeyAliasType)
–
The keyARN of the MAC generation encryption key.
-
message_data
(MessageDataType)
–
The data for which a MAC is under generation. This value must be hexBinary.
-
generation_attributes
(MacAttributes)
–
The attributes and data values to use for MAC generation within Amazon Web Services Payment Cryptography.
-
mac_length
(Optional[IntegerRangeBetween4And32], default:
None
)
–
The length of a MAC under generation.
Raises:
Source code in docs_src/capo_payment_cryptography_data/_services/async_payment_cryptography_data.py
| async def generate_mac(
self,
key_identifier: "capo_payment_cryptography_data.types.key_arn_or_key_alias_type.KeyArnOrKeyAliasType",
message_data: "capo_payment_cryptography_data.types.message_data_type.MessageDataType",
generation_attributes: "capo_payment_cryptography_data.types.mac_attributes.MacAttributes",
*,
config_overrides: Optional[AsyncPaymentCryptographyDataClientConfig] = None,
mac_length: Optional[
"capo_payment_cryptography_data.types.integer_range_between4_and32.IntegerRangeBetween4And32"
] = None,
) -> "capo_payment_cryptography_data.types.generate_mac_output.GenerateMacOutput":
"""<p>Generates a Message Authentication Code (MAC) cryptogram within Amazon Web Services Payment Cryptography. </p> <p>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.</p> <p>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 <code>KeyUsage</code> such as <code>TR31_M7_HMAC_KEY</code> for HMAC generation, and the key must have <code>KeyModesOfUse</code> set to <code>Generate</code>.</p> <p>For information about valid keys for this operation, see <a href="https://docs.aws.amazon.com/payment-cryptography/latest/userguide/keys-validattributes.html">Understanding key attributes</a> and <a href="https://docs.aws.amazon.com/payment-cryptography/latest/userguide/crypto-ops-validkeys-ops.html">Key types for specific data operations</a> in the <i>Amazon Web Services Payment Cryptography User Guide</i>. </p> <p> <b>Cross-account use</b>: This operation supports cross-account use when the key has a resource-based policy that grants access. For more information, see <a href="https://docs.aws.amazon.com/payment-cryptography/latest/userguide/security_iam_resource-based-policies.html">Resource-based policies</a>.</p> <p> <b>Related operations:</b> </p> <ul> <li> <p> <a>VerifyMac</a> </p> </li> </ul>
Args:
key_identifier: <p>The <code>keyARN</code> of the MAC generation encryption key.</p>
message_data: <p>The data for which a MAC is under generation. This value must be hexBinary.</p>
generation_attributes: <p>The attributes and data values to use for MAC generation within Amazon Web Services Payment Cryptography.</p>
mac_length: <p>The length of a MAC under generation.</p>
Raises:
capo_payment_cryptography_data.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient access to perform this action.</p>
capo_payment_cryptography_data.errors.internal_server_exception.InternalServerException: <p>The request processing has failed because of an unknown error, exception, or failure.</p>
capo_payment_cryptography_data.errors.resource_not_found_exception.ResourceNotFoundException: <p>The request was denied due to an invalid resource error.</p>
capo_payment_cryptography_data.errors.throttling_exception.ThrottlingException: <p>The request was denied due to request throttling.</p>
capo_payment_cryptography_data.errors.validation_exception.ValidationException: <p>The request was denied due to an invalid request error.</p>
capo_payment_cryptography_data.errors.UnknownServiceError: The service returned an error code this client does not model.
"""
async def _handler(
req: "AsyncOperationRequest[capo_payment_cryptography_data.types.generate_mac_input.GenerateMacInput]",
) -> AsyncOperationResponse[
"capo_payment_cryptography_data.types.generate_mac_output.GenerateMacOutput"
]:
import capo_payment_cryptography_data._operations.payment_cryptography_data_plane.generate_mac
(
output,
http_response,
) = await capo_payment_cryptography_data._operations.payment_cryptography_data_plane.generate_mac.async_generate_mac(
req.options, req.input
)
return AsyncOperationResponse(output=output, response=http_response)
def _redact_input(
input_: "capo_payment_cryptography_data.types.generate_mac_input.GenerateMacInput",
) -> dict[str, Any]:
import capo_payment_cryptography_data.types.generate_mac_input
return capo_payment_cryptography_data.types.generate_mac_input.redact_sensitive(
input_
)
def _redact_output(
output: "capo_payment_cryptography_data.types.generate_mac_output.GenerateMacOutput",
) -> dict[str, Any]:
import capo_payment_cryptography_data.types.generate_mac_output
return capo_payment_cryptography_data.types.generate_mac_output.redact_sensitive(
output
)
interceptors_, options_ = self.operation_options(
config_overrides,
OperationLogging(
"GenerateMac", redact_input=_redact_input, redact_output=_redact_output
),
)
input_: capo_payment_cryptography_data.types.generate_mac_input.GenerateMacInput = {
"key_identifier": key_identifier,
"message_data": message_data,
"generation_attributes": generation_attributes,
}
if mac_length is not None:
input_["mac_length"] = mac_length
response = await aexecute_pipeline(
AsyncOperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
await response.response.aclose()
return response.output
|