-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a PublicKeyEncryptionService for easier ShadowFlow configur…
…ation through starter
- Loading branch information
1 parent
db57318
commit c004724
Showing
4 changed files
with
54 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/io/github/rabobank/shadow_tool/PublicKeyEncryptionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.rabobank.shadow_tool; | ||
|
||
import javax.crypto.Cipher; | ||
import java.security.GeneralSecurityException; | ||
import java.security.PublicKey; | ||
|
||
import static javax.crypto.Cipher.ENCRYPT_MODE; | ||
|
||
/** | ||
* A version of the Encryption Service that uses a {@link PublicKey} to encrypt the values. | ||
*/ | ||
public class PublicKeyEncryptionService extends DefaultEncryptionService { | ||
private static final String DEFAULT_ALGORITHM = "RSA"; | ||
private static final String DEFAULT_ALGORITHM_MODE_PADDING = | ||
DEFAULT_ALGORITHM + "/ECB/OAEPWITHSHA-256ANDMGF1PADDING"; | ||
|
||
public PublicKeyEncryptionService(final PublicKey publicKey) { | ||
super(createCipher(publicKey)); | ||
} | ||
|
||
private static Cipher createCipher(final PublicKey publicKey) { | ||
try { | ||
final var cipher = Cipher.getInstance(DEFAULT_ALGORITHM_MODE_PADDING); | ||
cipher.init(ENCRYPT_MODE, publicKey); | ||
return cipher; | ||
} catch (final GeneralSecurityException e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters