11package utilities .JWEResponse ;
22
33import com .cybersource .authsdk .core .MerchantConfig ;
4+ import com .nimbusds .jose .JOSEException ;
45import org .apache .logging .log4j .LogManager ;
56import org .apache .logging .log4j .Logger ;
67import utilities .JWEResponse .JWEException .JWEException ;
78
89import java .io .IOException ;
910import java .security .NoSuchAlgorithmException ;
11+ import java .security .PrivateKey ;
1012import java .text .ParseException ;
1113
1214public 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