# Decrypt the Payload source: https://developer.mastercard.com/mastercard-checkout-solutions/tutorial/integrate_apis/step8/index.md ## Step 8. Decrypt the Payload {#step-8-decrypt-the-payload} Decrypt the `encryptedPayload` using your private key from the Payload Encryption public / private key pair. Mastercard uses the public key of this key-pair to encrypt response payloads containing payment card credentials. See [Key Management](https://developer.mastercard.com/mastercard-checkout-solutions/tutorial/key-management/index.md) to understand more about which keys to use to decrypt the payload. Mastercard returns the payload in the most secure format possible and in accordance with the `DpaTransactionOptions.PaymentOptions.dynamicDataType` parameter passed in the [JavaScript Request](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/common-objects/index.md#payment-options) ([checkout()](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/checkout-method/index.md) or [init()](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/init/index.md) methods). The values in [dynamicDataType](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/common-objects/index.md#payment-options) derive the payload format returned by Mastercard, detailed in the table below: | dynamicDataType | Description | Payload format | |----------------------------------------|--------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | CARD_APPLICATION_CRYPTOGRAM_SHORT_FORM | Payment authorization using token \& DSRP cryptogram passed in **token** and **dynamicData** objects respectively. | **DSRP** : Dynamic Secure Remote Payments (DSRP) cryptogram is a type of dynamic data which the Integrator will have to pass within Dynamic Payment Data field (DE104 SE001) of the payment authorization request. This cryptogram is base64 encoded and can be up to 32 characters in length. It is passed within the `DpaTransactionOptions.PaymentOptions.dynamicDataType` parameter in the [SDK Request](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/common-objects/index.md#payment-options) in either [checkout()](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/checkout-method/index.md) or [init()](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/init/index.md) method. Note: * While opting for transaction authentication, ensure that the **dynamicDataType** is `CARD_APPLICATION_CRYPTOGRAM_SHORT_FORM` in payment options. The authenticated payload will include cloud token \& DSRP cryptogram as the response. See [Step 5](https://developer.mastercard.com/mastercard-checkout-solutions/tutorial/integrate_apis/step5/index.md) for integration details. * Integrators that support dual payload will receive a second payment credential in the **card** object, along with the **token** object. This payment credential should be used for additional cases outside of payment authorization. Work with your [Mastercard representative](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/support/index.md#get-help) for more details. | | NONE | Payment authorization using PAN passed in **card** object. | **FPAN** : Integrators must pass this value when FPAN data is requested in `DpaTransactionOptions.PaymentOptions.dynamicDataType` parameter in either [checkout()](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/checkout-method/index.md) or [init()](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/init/index.md) methods. For countries that support only tokens (not FPANs), payment authorization is done using the token passed in **card** object. Optionally, merchants can pass Dynamic Token Verification Code (DTVC) present in **dynamicData** object as part of payment authorization in place of CVC2. | Diagram encryption_decryption 1. For decrypting the payload, you can use [Mastercard's encryption/decryption libraries](https://github.com/Mastercard?&q=client-encryption) 2. [Add the library](https://github.com/Mastercard/oauth1-signer-java#maven) to your project. 3. Define `util`, which will set the JWE Decryption configuration as per instructions defined in the library. ```Java private static JweConfig decryptionConfig; // Configuration defined by library public static JweConfig getDecryptionConfig() throws Exception { if (ObjectUtils.isEmpty(decryptionConfig)) { File decryptionCert = ResourceUtils.getFile("{{Decryption Certificate Path}}"); //.p12 file PrivateKey decryptionKey = EncryptionUtils.loadDecryptionKey( decryptionCert.getPath(), {{decryptionCertAlias}}, {{decryptionCertPassword}}); decryptionConfig = JweConfigBuilder.aJweEncryptionConfig() .withDecryptionKey(decryptionKey) .withDecryptionPath("$.encryptedPayload", "$") .withEncryptedValueFieldName("encryptedPayload") .build(); } return decryptionConfig; } ``` 4. Define a service interface and implementation for decryption using configuration defined in util. 4.1. Service Interface: To define behavior and structure of the decryption function. ```Java DecryptedPayloadDTO getDecryptedPayload(clicktopayResponseDTO clicktopayResponseDTO) throws Exception; ``` 4.2. Service Implementation: Implement service function as per the defined interface. ```Java public DecryptedPayloadDTO getDecryptedPayload(clicktopayResponseDTO clicktopayResponseDTO) throws Exception { JweConfig jweConfig = clicktopayUtils.getDecryptionConfig(); String payload = JweEncryption.decryptPayload(new Gson().toJson(clicktopayResponseDTO), jweConfig); DecryptedPayloadDTO decryptedPayload = new Gson().fromJson(payload,DecryptedPayloadDTO.class) return decryptedPayload; } ``` When the `encryptedPayload` field is decrypted, you will see a JSON object containing transaction information. * DSRP * PAN * PAN(Token-Only) * DSRP+PAN ```DSRP // DSRP cryptogram in the dynamicData object { "token": { "paymentToken": "************3165", "tokenExpirationMonth": "07", "tokenExpirationYear": "22", "paymentAccountReference": "50017Q9JP3JRJXIZ1BXQL2MKMX4LE" }, "shippingAddress": { "addressId": "adb12da8-474b-4e53-9c3b-5541af7c27bf", "name": "John doe", "line1": "test address", "city": "New York", "state": "NY", "countryCode": "US", "zip": "10011" }, "consumerEmailAddress": "johndoe@dummyemail.com", "consumerFirstName": "john", "consumerLastName": "doe", "consumerFullName": "john doe", "consumerMobileNumber": { "countryCode": "1", "phoneNumber": "9912797896" }, "srcTokenResultsData": { "unpredictableNumber": "63f43cff", "tokenRequesterId": "50123197928" }, "dynamicData": { "dynamicDataValue": "AIrqb3XZSbgpAAl2lQeDGgADFA==", "dynamicDataType": "CARD_APPLICATION_CRYPTOGRAM_SHORT_FORM" }, "billingAddress": { "addressId": "3374e6e9-293a-4612-aa5d-0e42a8ff7aae", "name": "John doe", "line1": "test address", "city": "New York", "state": "NY", "countryCode": "US", "zip": "10011" } } ``` ```PAN // Contains the PAN card object { "card": { "primaryAccountNumber": "5120350100064537", "panExpirationMonth": "08", "panExpirationYear": "23", "cardholderFullName": "John Doe", "cardholderFirstName": "John", "cardholderLastName": "Doe", "billingAddress": { "addressId": "ace92264-46eb-4cd8-b9b5-f2eff15b5ad8", "name": "John doe", "line1": "100 5th Avenue", "line2": "Floor 10", "city": "New York City", "state": "NY", "countryCode": "US", "zip": "10011" } }, "shippingAddress": { "addressId": "20a3c19f-934d-4c9a-89c1-864e360da387", "name": "John doe", "line1": "100 5th Avenue", "line2": "Floor 10", "city": "New York City", "state": "NY", "countryCode": "US", "zip": "10011" }, "consumerEmailAddress": "johndoe@dummyemail.com", "consumerFirstName": "john", "consumerLastName": "doe", "consumerFullName": "john doe", "consumerMobileNumber": { "countryCode": "1", "phoneNumber": "9912797895" }, "billingAddress": { "addressId": "ace92264-46eb-4cd8-b9b5-f2eff15b5ad8", "name": "John doe", "line1": "100 5th Avenue", "line2": "Floor 10", "city": "New York City", "state": "NY", "countryCode": "US", "zip": "10011" } } ``` ```PAN(Token-Only) // Contains Static token data and a Dynamic Token Verification Code { "card": { "primaryAccountNumber": "5120350100064537", "panExpirationMonth": "07", "panExpirationYear": "22", "cardholderFullName": "John Doe", "cardholderFirstName": "John", "cardholderLastName": "Doe", "billingAddress": { "addressId": "ace92264-46eb-4cd8-b9b5-f2eff15b5ad8", "name": "John doe", "line1": "100 5th Avenue", "line2": "Floor 10", "city": "New York City", "state": "NY", "countryCode": "US", "zip": "10011" } }, "shippingAddress": { "addressId": "20a3c19f-934d-4c9a-89c1-864e360da387", "name": "John doe", "line1": "100 5th Avenue", "line2": "Floor 10", "city": "New York City", "state": "NY", "countryCode": "US", "zip": "10011" }, "consumerEmailAddress": "johndoe@dummyemail.com", "consumerFirstName": "john", "consumerLastName": "doe", "consumerFullName": "john doe", "consumerMobileNumber": { "countryCode": "1", "phoneNumber": "9912797895" }, dynamicData": { "dynamicDataValue": 123, "dynamicDataType": "DYNAMIC_CARD_SECURITY_CODE" }, "billingAddress": { "addressId": "ace92264-46eb-4cd8-b9b5-f2eff15b5ad8", "name": "John doe", "line1": "100 5th Avenue", "line2": "Floor 10", "city": "New York City", "state": "NY", "countryCode": "US", "zip": "10011" } } ``` ```DSRP+PAN // Contains DSRP cryptogram in the dynamicData object and PAN in the card object { "card": { "primaryAccountNumber": "5120350100064537", "panExpirationMonth": "12", "panExpirationYear": "2025", "cardholderFullName": "John Doe", "cardholderFirstName": "John", "cardholderLastName": "Doe", "billingAddress": { "addressId": "4b870cd2-bc3f-46b1-952d-3da8f1b61907", "name": "John Doe", "line1": "150 5th Avenue", "city": "New York", "state": "NY", "countryCode": "US", "zip": "10011", "createTime": "2024-06-28T09:58:21.799Z" }, "paymentAccountReference": "5001CVSZVSHRWCG6YCKZD68DX3S43" }, "token": { "paymentToken": "************2505", "tokenExpirationMonth": "07", "tokenExpirationYear": "2027", "paymentAccountReference": "5001CVSZVSHRWCG6YCKZD68DX3S43", "panSequenceNumber": "00" }, "shippingAddress": { "addressId": "78afb7ed-613e-4289-b7c4-633342d0d34c", "name": "John Doe", "line1": "1 Angel Lane", "city": "London", "countryCode": "GB", "zip": "EC4R3AB", "createTime": "2024-07-03T12:06:34.993Z", "lastUsedTime": "2024-07-23T10:11:13.017Z" }, "consumerEmailAddress": "john.doe@mastercard.com", "consumerFirstName": "John", "consumerLastName": "Doe", "consumerFullName": "John Doe", "consumerMobileNumber": { "countryCode": "44", "phoneNumber": "7966778607" }, "srcTokenResultsData": { "unpredictableNumber": "1410ba3f" }, "dynamicData": { "dynamicDataValue": "AIzSpM52zu+PABIUELo/AAADFA==", "dynamicDataType": "CARD_APPLICATION_CRYPTOGRAM_SHORT_FORM" } } ``` | Field | Description | |------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| | **token** object | Indicates that the transaction has been tokenized. | | ↳ **paymentToken** | A 16 digit token rather than a PAN. | | ↳ **tokenExpirationMonth** ↳ **tokenExpirationYear** | Parameters which provide the tokenized values for digitized card. | | ↳ **paymentAccountReference** | Non-transactable value that is paired with a PAN and is linked to any token created that represents that PAN. | | **dynamicData** object | A cryptogram object. | | ↳ **dynamicDataValue** | DSRP: Containing the 32 char DSRP cryptogram in base64. | | ↳ **dynamicDataType** | `CARD_APPLICATION_CRYPTOGRAM_SHORT_FORM` indicates DSRP. `DYNAMIC_CARD_SECURITY_CODE` indicates DTVC. DTVC will be provided for PAN (token-only) countries also. | | **srcTokenResultsData** object | Additional token data. | | ↳ **tokenRequesterId** | Token Requester identifier. | | ↳ **unpredictableNumber** | Unpredictable Number used to generate this cryptogram. | Once the Mastercard Checkout Solution receives the payload response for a transaction, they can proceed to make a payment authorization with their acquirer or payment provider.