

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 驗證 EMV ARQC 並產生 ARPC
<a name="use-cases-issuers.generalfunctions.arqc"></a>

[ARQC](terminology.md#terms.arqc) (Authorization Request Cryptogram) 是由 EMV （晶片） 卡產生的密碼編譯，用於驗證交易詳細資訊以及授權卡的使用。它包含來自卡片、終端機和交易本身的資料。

在後端的驗證時間，相同的輸入會提供給 AWS 付款密碼編譯，密碼編譯會在內部重新建立，並與交易提供的值進行比較。就這個意義而言，它類似於 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/pw3s6nl62t5ushfk*。在下一個步驟中，您需要用到。

## 產生 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"
}
```