forked from eventuate-clients/eventuate-client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eventuate-clients#9: Enhancing the Eventuate Java Client According GD…
…PR. Added encryption to the eventuate jdbc access.
- Loading branch information
Showing
10 changed files
with
275 additions
and
38 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
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
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
47 changes: 47 additions & 0 deletions
47
...-impl/src/main/java/io/eventuate/javaclient/commonimpl/encryption/EncryptedEventData.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,47 @@ | ||
package io.eventuate.javaclient.commonimpl.encryption; | ||
|
||
import io.eventuate.javaclient.commonimpl.JSonMapper; | ||
|
||
public class EncryptedEventData { | ||
public static String ENCRYPTED_EVENT_DATA_STRING_PREFIX = "__ENCRYPTED__"; | ||
|
||
private String encryptionKeyId; | ||
private String data; | ||
|
||
public EncryptedEventData() { | ||
} | ||
|
||
public EncryptedEventData(String encryptionKeyId, String data) { | ||
this.encryptionKeyId = encryptionKeyId; | ||
this.data = data; | ||
} | ||
|
||
public static boolean checkIfEventDataStringIsEncrypted(String eventData) { | ||
return eventData.startsWith(ENCRYPTED_EVENT_DATA_STRING_PREFIX); | ||
} | ||
|
||
public static EncryptedEventData fromEventDataString(String eventData) { | ||
String json = eventData.substring(ENCRYPTED_EVENT_DATA_STRING_PREFIX.length()); | ||
return JSonMapper.fromJson(json, EncryptedEventData.class); | ||
} | ||
|
||
public String getEncryptionKeyId() { | ||
return encryptionKeyId; | ||
} | ||
|
||
public void setEncryptionKeyId(String encryptionKeyId) { | ||
this.encryptionKeyId = encryptionKeyId; | ||
} | ||
|
||
public String getData() { | ||
return data; | ||
} | ||
|
||
public void setData(String data) { | ||
this.data = data; | ||
} | ||
|
||
public String asString() { | ||
return ENCRYPTED_EVENT_DATA_STRING_PREFIX + JSonMapper.toJson(this); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ommon-impl/src/main/java/io/eventuate/javaclient/commonimpl/encryption/EncryptionKey.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,33 @@ | ||
package io.eventuate.javaclient.commonimpl.encryption; | ||
|
||
public class EncryptionKey { | ||
private String id; | ||
private String key; | ||
private String salt; | ||
|
||
public EncryptionKey(String id, String key, String salt) { | ||
this.id = id; | ||
this.key = key; | ||
this.salt = salt; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getSalt() { | ||
return salt; | ||
} | ||
|
||
public void setSalt(String salt) { | ||
this.salt = salt; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...-impl/src/main/java/io/eventuate/javaclient/commonimpl/encryption/EncryptionKeyStore.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,5 @@ | ||
package io.eventuate.javaclient.commonimpl.encryption; | ||
|
||
public interface EncryptionKeyStore { | ||
EncryptionKey findEncryptionKeyById(String keyId); | ||
} |
13 changes: 13 additions & 0 deletions
13
...-impl/src/main/java/io/eventuate/javaclient/commonimpl/encryption/EventDataEncryptor.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,13 @@ | ||
package io.eventuate.javaclient.commonimpl.encryption; | ||
|
||
import org.springframework.security.crypto.encrypt.Encryptors; | ||
|
||
public class EventDataEncryptor { | ||
public static String encrypt(EncryptionKey encryptionKey, String eventData) { | ||
return Encryptors.text(encryptionKey.getKey(), encryptionKey.getSalt()).encrypt(eventData); | ||
} | ||
|
||
public static String decrypt(EncryptionKey encryptionKey, String eventData) { | ||
return Encryptors.text(encryptionKey.getKey(), encryptionKey.getSalt()).decrypt(eventData); | ||
} | ||
} |
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
Oops, something went wrong.