Message-Level Encryption Using HTTP Signature Authentication
To use Message-Level Encryption (MLE) with HTTP Signature Authentication, you must send the
encrypted payload with the CEK generated for each transaction. The serialized
encrypted payload, the JWE, is passed as the request body.
Follow these steps to use MLE with HTTP Signature Authentication:
- Generate the JWE.Using the code shown here accomplishes these things:
- Generates and encrypts the CEK with the recipient's public key using the RSAES-OAEP algorithm.
- Produces the JWE encrypted key.
- Generates the encrypted payload with AES GCM using the CEK as the encryption key.
//This Java example uses the following Maven dependency: <dependency> <groupId>com.nimbusds</groupId> <artifactId>nimbus-jose-jwt</artifactId> <version>9.0</version> </dependency>customHeaders.put("iat", Instant.now().getEpochSecond()); JWEAlgorithm algo = JWEAlgorithm.RSA_OAEP_256; EncryptionMethod encryptionMethod = EncryptionMethod.A256GCM; String content = "{\"clientReferenceInformation\":{\"code\":\"TC50171_3\"}, \"processingInformation\":{\"commerceIndicator\":\"internet\"}, \"aggregatorInformation\":{\"subMerchant\":{\"cardAcceptorID\":\"1234567890\", \"country\":\"US\",\"phoneNumber\":\"650-432-0000\",\"address1\":\"900MetroCenter\", \"postalCode\":\"94404-2775\",\"locality\":\"FosterCity\",\"name\":\"VisaInc\", \"administrativeArea\":\"CA\",\"region\":\"PEN\",\"email\":\"\"}, \"name\":\"V-Internatio\",\"aggregatorID\":\"123456789\"}, \"orderInformation\":{\"billTo\":{\"country\":\"US\",\"lastName\":\"VDP\", \"address2\":\"Address2\",\"address1\":\"201S.DivisionSt.\",\"postalCode\":\"48104-2201\", \"locality\":\"AnnArbor\",\"administrativeArea\":\"MI\",\"firstName\":\"RTS\", \"phoneNumber\":\"999999999\",\"district\":\"MI\",\"buildingNumber\":\"123\", \"company\":\"Visa\",\"email\":\"\"},\"amountDetails\":{\"totalAmount\":\"102.21\", \"currency\":\"USD\"}},\"paymentInformation\":{\"card\":{\"expirationYear\":\"2031\", \"number\":\"5555555555554444\",\"securityCode\":\"123\", \"expirationMonth\":\"12\",\"type\":\"002\"}}}" public String encryptAttributeWithAlgo(String content, X509Certificate x509Certificate, JWEAlgorithm algo, EncryptionMethod encryptionMethod, Map<String, Object> customHeaders) { if (isNullOrEmpty(content)) { logger.error("empty or null content"); return null; } else if ( x509Certificate == null) { logger.error("public certificate is null"); return null; } String serialNumber = extractSerialNumberFromDN(x509Certificate); JWEObject jweObject = new JWEObject( new JWEHeader.Builder(algo, encryptionMethod) .contentType("JWT") // required to signal nested JWT .keyID(serialNumber) .customParams(customHeaders) .build(), new Payload(content)); jweObject = encrypt(jweObject, x509Certificate); return jweObject == null ? null : serializeToken(jweObject); } - Send the JWE as the body.HTTP Request Header: Content-Type: application/json v-c-merchant-id: testrest v-c-date: Mon, 12 Jun 2023 21:08:24 GMT host:apitest.cybersource.comdigest: SHA-256=1wk5Hls1qcbZtjYDldGyl3B2i92v4rOqXyx6twRboEs= signature: keyid="08c94330-f618-42a3-b09d-e1e43be5efda", algorithm="HmacSHA256", headers="host request-target digest v-c-merchant-id", signature="ldqJNbiFZ0ZhOHzhejvuAaNomlFmXv1xykNAEq7irn4=" HTTP Request Body: {"encryptedRequest":"eyJ2LWMtbWVyY2hhbnQtaWQiOiJtcG9zX3BheW1lbnRlY2giLCJ4NWMiOlsiTUlJRE5UQ0NBaDJnQXdJQkFnSVdNVFkwT1RFNU1ERXhNREEwTkRBd056Y3lOakF6T0RBTkJna3Foa2lHOXcwQkFRc0ZBREJwTVFzd0NRWURWUVFHRXdKVlV6RU5NQXNHQTFVRUNnd0VWbWx6WVRFVU1CSUdBMVVFQ3d3TFEzbGlaWEpUYjNWeVkyVXhOVEF6QmdOVkJBTU1MRU41WW1WeVUyOTFjbU5sSUZSeVlXNXpZV04wYVc5dVlXd2dUbTl1VUhKdlpDQkpjM04xYVc1bklFTkJNQjRYRFRJeU1EUXdOVEl3TWpFMU1Wb1hEVEkxTURRd05USXdNakUxTVZvd1BqRWJNQmtHQTFVRUF3d1NRM2xpWlhKVGIzVnlZMlZmVTBwRFgxVlRNUjh3SFFZRFZRUUZFeFl4TmpRNU1Ua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