Skip to content

Commit 305b144

Browse files
committed
Deprecated method for JWE decryption
Added new method using PrivateKey parameter
1 parent 7b5de7b commit 305b144

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main/java/utilities/JWEResponse/JWEUtility.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package utilities.JWEResponse;
22

33
import com.cybersource.authsdk.core.MerchantConfig;
4+
import com.nimbusds.jose.JOSEException;
45
import org.apache.logging.log4j.LogManager;
56
import org.apache.logging.log4j.Logger;
67
import utilities.JWEResponse.JWEException.JWEException;
78

89
import java.io.IOException;
910
import java.security.NoSuchAlgorithmException;
11+
import java.security.PrivateKey;
1012
import java.text.ParseException;
1113

1214
public class JWEUtility {
1315
private static final Logger logger = LogManager.getLogger(JWEUtility.class);
1416

17+
/**
18+
* This method has been marked as Deprecated and will be removed in coming releases.
19+
*
20+
* @deprecated use {@link #decryptJWEResponse(PrivateKey, String)} instead.
21+
*/
22+
@Deprecated
1523
public static String decryptJWEResponse(String encodedResponse, MerchantConfig merchantConfig) throws JWEException {
1624
try {
1725
return com.cybersource.authsdk.util.JWEUtility.decryptJWEUsingPEM(merchantConfig, encodedResponse);
@@ -30,4 +38,19 @@ public static String decryptJWEResponse(String encodedResponse, MerchantConfig m
3038
throw new JWEException("Exception occurred while decrypting the response", exception);
3139
}
3240
}
41+
42+
public static String decryptJWEResponse(PrivateKey privateKey, String encodedResponse) throws JWEException {
43+
try {
44+
return com.cybersource.authsdk.util.JWEUtility.decryptJWEUsingPrivateKey(privateKey, encodedResponse);
45+
} catch (ParseException exception) {
46+
logger.error("ParseException: Unparsable decrypted response", exception);
47+
throw new JWEException("Unparsable decrypted response", exception);
48+
} catch (JOSEException exception) {
49+
logger.error("JOSEException: Could not able to decrypt the JWE response", exception);
50+
throw new JWEException("Could not able to decrypt the JWE response", exception);
51+
} catch (Exception exception) {
52+
logger.error("JWE internal SDK exception", exception);
53+
throw new JWEException("Exception occurred while decrypting the response", exception);
54+
}
55+
}
3356
}

0 commit comments

Comments
 (0)