forked from Limework/RediSkript
Finish AES encryption
This commit is contained in:
parent
a6b6379234
commit
9d7fbcd33b
@ -7,8 +7,8 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="61139119-6327-48a6-9183-0df6346ed8d8" name="Default Changelist" comment="">
|
<list default="true" id="61139119-6327-48a6-9183-0df6346ed8d8" name="Default Changelist" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/artifacts/SkLimework_jar.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/artifacts/SkLimework_jar.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/SkLimework.jar" beforeDir="false" afterPath="$PROJECT_DIR$/SkLimework.jar" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/AddonPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/AddonPlugin.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/AddonPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/limework/skLimework/AddonPlugin.java" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
@ -40,7 +40,8 @@ public class AddonPlugin extends JavaPlugin {
|
|||||||
private JedisPool jedisPool;
|
private JedisPool jedisPool;
|
||||||
private RedisSub redisSub;
|
private RedisSub redisSub;
|
||||||
private ExecutorService service;
|
private ExecutorService service;
|
||||||
private Cipher cipher;
|
private Cipher encryptionCipher;
|
||||||
|
private Cipher decryptionCipher;
|
||||||
private boolean encryptionEnabled;
|
private boolean encryptionEnabled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -66,14 +67,29 @@ public class AddonPlugin extends JavaPlugin {
|
|||||||
key = Arrays.copyOf(key, 16);
|
key = Arrays.copyOf(key, 16);
|
||||||
SecretKeySpec encryptionKey = new SecretKeySpec(key, "AES");
|
SecretKeySpec encryptionKey = new SecretKeySpec(key, "AES");
|
||||||
|
|
||||||
cipher = null;
|
encryptionCipher = null;
|
||||||
try {
|
try {
|
||||||
cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
encryptionCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (NoSuchPaddingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, encryptionKey);
|
encryptionCipher.init(Cipher.ENCRYPT_MODE, encryptionKey);
|
||||||
|
} catch (InvalidKeyException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
decryptionCipher = null;
|
||||||
|
try {
|
||||||
|
decryptionCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (NoSuchPaddingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
decryptionCipher.init(Cipher.DECRYPT_MODE, encryptionKey);
|
||||||
} catch (InvalidKeyException e) {
|
} catch (InvalidKeyException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -145,7 +161,7 @@ public class AddonPlugin extends JavaPlugin {
|
|||||||
public String encrypt(String message) {
|
public String encrypt(String message) {
|
||||||
String encrypted = null;
|
String encrypted = null;
|
||||||
try {
|
try {
|
||||||
encrypted = Base64.getEncoder().encodeToString(cipher.doFinal(message.getBytes(StandardCharsets.UTF_8)));
|
encrypted = Base64.getEncoder().encodeToString(encryptionCipher.doFinal(message.getBytes(StandardCharsets.UTF_8)));
|
||||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -155,7 +171,7 @@ public class AddonPlugin extends JavaPlugin {
|
|||||||
public String decrypt(String message) {
|
public String decrypt(String message) {
|
||||||
String decrypted = null;
|
String decrypted = null;
|
||||||
try {
|
try {
|
||||||
decrypted = new String(cipher.doFinal(Base64.getDecoder().decode(message)), StandardCharsets.UTF_8);
|
decrypted = new String(decryptionCipher.doFinal(Base64.getDecoder().decode(message)), StandardCharsets.UTF_8);
|
||||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user