Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvisser committed Oct 2, 2023
1 parent 89faf81 commit e8d2985
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/main/java/io/github/rabobank/shadow_tool/ShadowFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

import javax.crypto.Cipher;
import java.security.PublicKey;
import java.util.Collection;
import java.util.Map;
Expand Down Expand Up @@ -275,7 +276,9 @@ public ShadowFlowBuilder<T> withExecutorService(final ExecutorService executorSe
*/
public ShadowFlowBuilder<T> withEncryption(final PublicKey publicKey) {
try {
this.encryptionService = new EncryptionService(publicKey);
final var cipher = Cipher.getInstance(DEFAULT_ALGORITHM_MODE_PADDING);
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
withCipher(cipher);
} catch (Exception e) {
logger.error("Invalid encryption setup. Encryption and logging of values is disabled", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.security.PublicKey;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class EncryptionServiceTest {
private static final PrivateKey PRIVATE_KEY;
Expand All @@ -35,9 +36,9 @@ void encryptAndDecrypt() throws Exception {
encryptCipher.init(Cipher.ENCRYPT_MODE, PUBLIC_KEY);
final var encryptionService = new DefaultEncryptionService(encryptCipher);
final var plainDifferences = "'place' changed: 'Dintelooord' -> 'Dinteloord'\n" +
"'madrigals' collection changes :\n" +
" 1. 'Bruno' changed to 'Mirabel'\n" +
" 0. 'Bruno' added";
"'madrigals' collection changes :\n" +
" 1. 'Bruno' changed to 'Mirabel'\n" +
" 0. 'Bruno' added";
final var encryptedDifferences = encryptionService.encrypt(plainDifferences);
//Decrypt and verify
final var decryptCipher = Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING");
Expand All @@ -53,9 +54,9 @@ void encryptAndForgotToInitCipher() throws Exception {
final var encryptCipher = Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING");
final var encryptionService = new DefaultEncryptionService(encryptCipher);
final var plainDifferences = "'place' changed: 'Dintelooord' -> 'Dinteloord'\n" +
"'madrigals' collection changes :\n" +
" 1. 'Bruno' changed to 'Mirabel'\n" +
" 0. 'Bruno' added";
"'madrigals' collection changes :\n" +
" 1. 'Bruno' changed to 'Mirabel'\n" +
" 0. 'Bruno' added";
final var exception = assertThrows(SecurityException.class, () -> encryptionService.encrypt(plainDifferences));
assertEquals("java.lang.IllegalStateException: Cipher not initialized", exception.getMessage());
}
Expand Down

0 comments on commit e8d2985

Please sign in to comment.