From 1ea6bd61f831fdb7522638eb863ee469aedfef28 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 22 Dec 2024 16:17:58 +0100 Subject: [PATCH] Fix concurrent cipher usage --- .../fightsystem/utils/TechHiderWrapper.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java index 68781d46..a01e61b4 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java @@ -37,10 +37,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; +import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; import java.io.File; import java.io.IOException; @@ -56,16 +53,15 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati private final ConcurrentHashMap hiddenRegion = new ConcurrentHashMap<>(); private final ConcurrentHashMap patterns = new ConcurrentHashMap<>(); private final TechHider techHider; - private final Cipher cipher; + private final SecretKey key; public TechHiderWrapper() { super(ENABLED, FightState.Schem); techHider = new TechHider(this, Config.ObfuscateWith, Config.HiddenBlocks, Config.HiddenBlockEntities); try { - cipher = Cipher.getInstance("AES_256/CFB/NoPadding"); - cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(Files.readAllBytes(new File(System.getProperty("user.home"), "hullhider.key").toPath()), "AES")); - } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IOException e) { + key = new SecretKeySpec(Files.readAllBytes(new File(System.getProperty("user.home"), "hullhider.key").toPath()), "AES"); + } catch (IOException e) { throw new SecurityException(e); } @@ -153,8 +149,10 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati }; try { + Cipher cipher = Cipher.getInstance("AES_256/CFB/NoPadding"); + cipher.init(Cipher.ENCRYPT_MODE, key); bytes = cipher.doFinal(bytes); - } catch (IllegalBlockSizeException | BadPaddingException e) { + } catch (IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) { throw new SecurityException(e); }