diff --git a/.idea/discord.xml b/.idea/discord.xml
new file mode 100644
index 0000000..59b11d1
--- /dev/null
+++ b/.idea/discord.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6147b43..1b9fe14 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,11 +7,13 @@
+
-
+
+
+
-
@@ -35,6 +37,10 @@
+
+
+
+
@@ -52,18 +58,6 @@
-
-
-
@@ -84,6 +78,9 @@
+
+
+
diff --git a/src/main/java/net/limework/skLimework/AddonPlugin.java b/src/main/java/net/limework/skLimework/AddonPlugin.java
index b42b657..e7a66fe 100644
--- a/src/main/java/net/limework/skLimework/AddonPlugin.java
+++ b/src/main/java/net/limework/skLimework/AddonPlugin.java
@@ -11,12 +11,25 @@ import net.limework.skLimework.elements.EvtRedis;
import net.limework.skLimework.elements.ExprChannel;
import net.limework.skLimework.elements.ExprMessage;
import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.spec.SecretKeySpec;
import java.beans.Expression;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+import java.util.Base64;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -27,12 +40,43 @@ public class AddonPlugin extends JavaPlugin {
private JedisPool jedisPool;
private RedisSub redisSub;
private ExecutorService service;
-
+ private Cipher cipher;
+ private boolean encryptionEnabled;
@Override
public void onEnable(){
instance = this;
this.saveDefaultConfig();
+ FileConfiguration config = this.getConfig();
+ encryptionEnabled = config.getBoolean("Redis.EncryptMessages");
+ if (encryptionEnabled) {
+ // AES-128 encryption
+ String configKey = config.getString("Redis.EncryptionKey");
+ byte[] key = null;
+ assert configKey != null;
+ key = configKey.getBytes(StandardCharsets.UTF_8);
+ MessageDigest sha = null;
+ try {
+ sha = MessageDigest.getInstance("SHA-1");
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ }
+ key = Arrays.copyOf(key, 16);
+ SecretKeySpec encryptionKey = new SecretKeySpec(key, "AES");
+
+ cipher = null;
+ try {
+ cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+ } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
+ e.printStackTrace();
+ }
+ try {
+ cipher.init(Cipher.ENCRYPT_MODE, encryptionKey);
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ }
+ }
+
addon = Skript.registerAddon(this);
try { addon.loadClasses("net.limework.skLimework", "elements");
Skript.registerEvent("redis message", EvtRedis.class, onRedisMessage.class, "redis message");
@@ -51,8 +95,7 @@ public class AddonPlugin extends JavaPlugin {
}
}, 0);
-
-
+
} catch (IOException e) { e.printStackTrace(); }
JedisPoolConfig jconfig = new JedisPoolConfig();
@@ -94,4 +137,26 @@ public class AddonPlugin extends JavaPlugin {
}
public JedisPool getJedisPool() { return jedisPool; }
+
+ public boolean isEncryptionEnabled() { return encryptionEnabled; }
+
+ public String encrypt(String message) {
+ String encrypted = null;
+ try {
+ encrypted = Base64.getEncoder().encodeToString(cipher.doFinal(message.getBytes(StandardCharsets.UTF_8)));
+ } catch (IllegalBlockSizeException | BadPaddingException e) {
+ e.printStackTrace();
+ }
+ return encrypted;
+ }
+
+ public String decrypt(String message) {
+ String decrypted = null;
+ try {
+ decrypted = new String(cipher.doFinal(Base64.getDecoder().decode(message)), StandardCharsets.UTF_8);
+ } catch (IllegalBlockSizeException | BadPaddingException e) {
+ e.printStackTrace();
+ }
+ return decrypted;
+ }
}
diff --git a/src/main/java/net/limework/skLimework/Events/onRedisMessage.java b/src/main/java/net/limework/skLimework/Events/onRedisMessage.java
index 388caae..eade583 100644
--- a/src/main/java/net/limework/skLimework/Events/onRedisMessage.java
+++ b/src/main/java/net/limework/skLimework/Events/onRedisMessage.java
@@ -1,5 +1,7 @@
package net.limework.skLimework.Events;
+import net.limework.skLimework.AddonPlugin;
+import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@@ -13,7 +15,13 @@ public class onRedisMessage extends Event {
onRedisMessage(String channelName , String message) {
super(true);
this.channelName = channelName;
- this.message = message;
+ AddonPlugin instance = (AddonPlugin) Bukkit.getPluginManager().getPlugin("SKLimework");
+ assert instance != null;
+ if (instance.isEncryptionEnabled()) {
+ this.message = instance.decrypt(message);
+ } else {
+ this.message = message;
+ }
}
diff --git a/src/main/java/net/limework/skLimework/elements/EffSendMessage.java b/src/main/java/net/limework/skLimework/elements/EffSendMessage.java
index 4c37b3e..96b4911 100644
--- a/src/main/java/net/limework/skLimework/elements/EffSendMessage.java
+++ b/src/main/java/net/limework/skLimework/elements/EffSendMessage.java
@@ -34,11 +34,16 @@ public class EffSendMessage extends Effect {
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aGBot&a] &cMessage Was empty Please check your code."));
return;
}
+ assert plugin != null;
plugin.getJedisExecutionService().execute(() -> {
Jedis j = plugin.getJedisPool().getResource();
JSONObject json = new JSONObject();
try {
- json.put("Message", message);
+ if (plugin.isEncryptionEnabled()) {
+ json.put("Message", plugin.encrypt(message));
+ } else {
+ json.put("Message", message);
+ }
json.put("Type", "Skript");
j.publish(channel, json.toString());
//System.out.println("SkriptSide sent MESSAGE: ["+ message + "] to channel: " + channel + " and json: \n" + json.toString());
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 69fec52..0b743d1 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -6,6 +6,9 @@ Redis:
Port: 6379
TimeOut: 40000
useSSL: true
+ #useful if SSL is disabled
+ EncryptMessages: false
+ EncryptionKey: "16CHARACTERS KEY"
Channels:
- "Channel1"