Skip to content

Commit 3142e3a

Browse files
authored
Throw a custom runtimeexception on decrypt failure (#1081)
1 parent 5c51622 commit 3142e3a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/main/java/formflow/library/data/SubmissionEncryptionService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.google.crypto.tink.JsonKeysetReader;
99
import com.google.crypto.tink.KeysetHandle;
1010
import com.google.crypto.tink.aead.AeadConfig;
11+
import formflow.library.exceptions.SubmissionDecryptionException;
1112
import java.io.IOException;
1213
import java.lang.reflect.Field;
1314
import java.security.GeneralSecurityException;
@@ -161,11 +162,11 @@ private String encryptString(String data) {
161162
}
162163
}
163164

164-
private String decryptString(String encryptedData) {
165+
private String decryptString(String fieldName, String encryptedData) {
165166
try {
166167
return new String(encDec.decrypt(Hex.decodeHex(encryptedData.toCharArray()), null));
167168
} catch (GeneralSecurityException | DecoderException e) {
168-
throw new RuntimeException(e);
169+
throw new SubmissionDecryptionException("Unable to decrypt " + fieldName, e);
169170
}
170171
}
171172

@@ -177,7 +178,7 @@ private void replaceValue(Field field, Map<String, Object> inputMap, EncryptionD
177178
inputMap.put(fieldName, encryptString(value));
178179
} else {
179180
String value = (String) inputMap.remove(field.getName() + ENCRYPT_SUFFIX);
180-
inputMap.put(fieldName, decryptString(value));
181+
inputMap.put(fieldName, decryptString(fieldName, value));
181182
}
182183
}
183184

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package formflow.library.exceptions;
2+
3+
public class SubmissionDecryptionException extends RuntimeException {
4+
public SubmissionDecryptionException(String message, Throwable cause) {
5+
super(message, cause);
6+
}
7+
}

0 commit comments

Comments
 (0)