

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 验证 EMV ARQC 并生成 ARPC
<a name="use-cases-issuers.generalfunctions.arqc"></a>

[ARQC](terminology.md#terms.arqc)（授权请求密码）是由EMV（芯片）卡生成的密码，用于验证交易细节以及授权卡的使用。它包含来自卡、终端和交易本身的数据。

在后端进行验证时，会向 P AWS ayment Cryptography 提供相同的输入，在内部重新创建密码，并将其与交易中提供的价值进行比较。从这个意义上讲，它类似于MAC。[EMV 4.4 Book 2](https://www.emvco.com/specifications/?post_id=80377) 定义了此函数的三个方面——用于生成一次性交易密钥的密钥派生方法（称为通用会话密钥——CSK）、最小有效载荷和生成响应的方法 (ARPC)。

 个别信用卡方案可以指定要合并的其他交易字段或这些字段的显示顺序。还存在其他（通常不推荐使用的）特定于方案的派生方案，本文档的其他部分对此进行了介绍。

有关更多信息，请参阅 API 指南[VerifyCardValidationData](https://docs.aws.amazon.com/payment-cryptography/latest/DataAPIReference/API_VerifyCardValidationData.html)中的。

## 创建密钥
<a name="use-cases-issuers.generalfunctions.arqc.setup"></a>

```
$ aws payment-cryptography create-key --exportable --key-attributes KeyAlgorithm=TDES_2KEY,KeyUsage=TR31_E0_EMV_MKEY_APP_CRYPTOGRAMS,KeyClass=SYMMETRIC_KEY,KeyModesOfUse='{DeriveKey=true}' --tags='[{"Key":"KEY_PURPOSE","Value":"CVN18"},{"Key":"CARD_BIN","Value":"12345678"}]'
```

响应会回显请求参数，包括后续调用的 ARN 以及密钥检查值 (KCV)。

```
{
                "Key": {
                    "KeyArn": "arn:aws:payment-cryptography:us-east-2:111122223333:key/pw3s6nl62t5ushfk",
                    "KeyAttributes": {
                        "KeyUsage": "TR31_E0_EMV_MKEY_APP_CRYPTOGRAMS",
                        "KeyClass": "SYMMETRIC_KEY",
                        "KeyAlgorithm": "TDES_2KEY",
                        "KeyModesOfUse": {
                            "Encrypt": false,
                            "Decrypt": false,
                            "Wrap": false,
                            "Unwrap": false,
                            "Generate": false,
                            "Sign": false,
                            "Verify": false,
                            "DeriveKey": true,
                            "NoRestrictions": false
                        }
                    },
                    "KeyCheckValue": "08D7B4",
                    "KeyCheckValueAlgorithm": "ANSI_X9_24",
                    "Enabled": true,
                    "Exportable": true,
                    "KeyState": "CREATE_COMPLETE",
                    "KeyOrigin": "AWS_PAYMENT_CRYPTOGRAPHY",
                    "CreateTimestamp": "2024-03-07T06:41:46.648000-07:00",
                    "UsageStartTimestamp": "2024-03-07T06:41:46.626000-07:00"
                }
            }
```

注意代表密钥的那个`KeyArn`，例如 *arn: aws: payment-cryptography: us-east-2:111122223333: key/pw3s6nl62* t5ushfk。您需要在下一步中执行该操作。

## 生成 ARQC
<a name="use-cases-issuers.generalfunctions.arqc.generate"></a>

ARQC 完全由 EMV 卡生成。因此， AWS 支付密码学没有生成此类有效载荷的工具。出于测试目的，在线提供了许多库，这些库可以生成适当的有效载荷以及各种方案通常提供的已知值。

## 验证 ARQC
<a name="use-cases-issuers.generalfunctions.arqc.verify"></a>

**Example**  
如果 AWS 支付密码学能够验证 ARQC，则会返回 http/200。在验证 ARQC 后，可以选择提供 ARPC（响应）并将其包含在响应中。  

```
$ aws payment-cryptography-data verify-auth-request-cryptogram --auth-request-cryptogram 61EDCC708B4C97B4 --key-identifier arn:aws:payment-cryptography:us-east-2:111122223333:key/pw3s6nl62t5ushfk --major-key-derivation-mode EMV_OPTION_A --transaction-data 00000000170000000000000008400080008000084016051700000000093800000B1F2201030000000000000000000000000000000000000000000000000000008000000000000000 --session-key-derivation-attributes='{"EmvCommon":{"ApplicationTransactionCounter":"000B", "PanSequenceNumber":"01","PrimaryAccountNumber":"9137631040001422"}}' --auth-response-attributes='{"ArpcMethod2":{"CardStatusUpdate":"12345678"}}'
```

```
{
    "KeyArn": "arn:aws:payment-cryptography:us-east-2:111122223333:key/pw3s6nl62t5ushfk",
    "KeyCheckValue": "08D7B4",
    "AuthResponseValue":"2263AC85"
}
```