1414import javax .crypto .spec .IvParameterSpec ;
1515import javax .crypto .spec .SecretKeySpec ;
1616import java .security .InvalidKeyException ;
17+ import java .security .PrivateKey ;
1718
1819import static com .mastercard .developer .encryption .FieldLevelEncryptionConfig .FieldValueEncoding ;
1920import static com .mastercard .developer .encryption .FieldLevelEncryptionParams .SYMMETRIC_KEY_TYPE ;
@@ -1035,7 +1036,7 @@ public void testDecryptPayload_ShouldKeepInputObject_WhenContainsAdditionalField
10351036 }
10361037
10371038 @ Test
1038- public void testDecryptPayload_ShouldOverwriteInputObject_WhenOutPathSameAsInPath () throws Exception {
1039+ public void testDecryptPayload_ShouldOverwriteInputObject_WhenOutPathSameAsInPath_ObjectData () throws Exception {
10391040
10401041 // GIVEN
10411042 String encryptedPayload = "{" +
@@ -1060,6 +1061,40 @@ public void testDecryptPayload_ShouldOverwriteInputObject_WhenOutPathSameAsInPat
10601061 assertEquals ("\" field2Value\" " , payloadObject .get ("encryptedData" ).getAsJsonObject ().get ("field2" ).toString ());
10611062 }
10621063
1064+ /**
1065+ * https://github.com/Mastercard/client-encryption-java/issues/3
1066+ */
1067+ @ Test
1068+ public void testDecryptPayload_ShouldOverwriteInputObject_WhenOutPathSameAsInPath_PrimitiveTypeData () throws Exception {
1069+
1070+ // GIVEN
1071+ String encryptedPayload = "{" +
1072+ " \" data\" : {" +
1073+ " \" encryptedData\" : {" +
1074+ " \" encryptedValue\" : \" Qiw1g87OCwa5/IXPC5nIJw==\" ," +
1075+ " \" iv\" : \" OZt7FRV644fEFbb75VNdjA==\" ," +
1076+ " \" encryptedKey\" : \" AyI8R1/ziGTZ6Uhy2JGsy+PYf+KXcrzn5v56tP3WnuFM2Qt24T9t4WXE+B1cqiDjo1LQIEgXJWZ5XX/fbYh/Y1qmycit/QmPVEjGqoKLNSB1Js00Cghyt7lChuSUIWRnYbNAa0q6EgPS5vyDrXDVZH0vkTM6egc7d76O9Sw+rXGzv9d9wiQlhxFXkb+GH/BCiswb064w53LcXdoBcup1sEEn6UIuORtiCGeQcNqS6yvkR3HWc0lrAJpCikJoTCMQli7MJYAVj+w4LZCUZMcwWMuiMhLQQdjTAhCCK9+fKItwA5xSDaXictspUALTi/drdcj2zXbxX3E2t+q1PgWPUg==\" ," +
1077+ " \" publicKeyFingerprint\" : \" 29f8a7cea970886829226864c79195088ee464a89d8bc835d392c1f6666326c6\" ," +
1078+ " \" oaepPaddingDigestAlgorithm\" : \" SHA256\" " +
1079+ " }" +
1080+ " }" +
1081+ "}" ;
1082+
1083+ PrivateKey decryptionKey = EncryptionUtils .loadDecryptionKey ("./src/test/resources/keys/pkcs8/github-issue#3.pem" );
1084+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
1085+ .withDecryptionKey (decryptionKey )
1086+ .withDecryptionPath ("$.data.encryptedData" , "$.data.encryptedData" )
1087+ .withFieldValueEncoding (FieldValueEncoding .BASE64 )
1088+ .build ();
1089+
1090+ // WHEN
1091+ String payload = FieldLevelEncryption .decryptPayload (encryptedPayload , config );
1092+
1093+ // THEN
1094+ JsonObject payloadObject = new Gson ().fromJson (payload , JsonObject .class );
1095+ assertEquals ("India" , payloadObject .get ("data" ).getAsJsonObject ().get ("encryptedData" ).getAsString ());
1096+ }
1097+
10631098 @ Test
10641099 public void testDecryptPayload_ShouldSupportRootAsInputPath () throws Exception {
10651100
0 commit comments