From 5b2a51a8b5e79b37159c3051bf748701aaa5c417 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 18 May 2025 17:46:15 +0200 Subject: [PATCH] remove unused EncryptUtil methods, rename --- common/src/common/network/NetConnection.java | 4 +-- common/src/common/util/EncryptUtil.java | 30 ++------------------ 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/common/src/common/network/NetConnection.java b/common/src/common/network/NetConnection.java index 5a0530a..a359d83 100755 --- a/common/src/common/network/NetConnection.java +++ b/common/src/common/network/NetConnection.java @@ -364,8 +364,8 @@ public class NetConnection extends SimpleChannelInboundHandler } public void startEncryption(SecretKey key) { - this.channel.pipeline().addBefore("splitter", "decrypt", new NettyEncryptionDecoder(EncryptUtil.createNetCipherInstance(Cipher.DECRYPT_MODE, key))); - this.channel.pipeline().addBefore("prepender", "encrypt", new NettyEncryptionEncoder(EncryptUtil.createNetCipherInstance(Cipher.ENCRYPT_MODE, key))); + this.channel.pipeline().addBefore("splitter", "decrypt", new NettyEncryptionDecoder(EncryptUtil.createCipher(Cipher.DECRYPT_MODE, key))); + this.channel.pipeline().addBefore("prepender", "encrypt", new NettyEncryptionEncoder(EncryptUtil.createCipher(Cipher.ENCRYPT_MODE, key))); } static class InboundHandlerTuplePacketListener diff --git a/common/src/common/util/EncryptUtil.java b/common/src/common/util/EncryptUtil.java index 3ef5080..2414eb5 100644 --- a/common/src/common/util/EncryptUtil.java +++ b/common/src/common/util/EncryptUtil.java @@ -49,33 +49,7 @@ public class EncryptUtil { return null; } } - - public static byte[] getServerIdHash(String id, PublicKey pubkey, SecretKey secret) { - try { - return digestOperation("SHA-1", new byte[][] {id.getBytes("ISO_8859_1"), secret.getEncoded(), pubkey.getEncoded()}); - } - catch(UnsupportedEncodingException e) { - Log.SYSTEM.error(e, "Konnte Server-Prüfwert nicht berechnen"); - return null; - } - } - - private static byte[] digestOperation(String algorithm, byte[]... data) { - try { - MessageDigest digest = MessageDigest.getInstance(algorithm); - - for(byte[] abyte : data) { - digest.update(abyte); - } - - return digest.digest(); - } - catch(NoSuchAlgorithmException e) { - Log.SYSTEM.error(e, "Konnte Prüfwert nicht berechnen"); - return null; - } - } - + public static PublicKey decodePublicKey(byte[] encoded) { try { EncodedKeySpec spec = new X509EncodedKeySpec(encoded); @@ -122,7 +96,7 @@ public class EncryptUtil { } } - public static Cipher createNetCipherInstance(int mode, Key key) { + public static Cipher createCipher(int mode, Key key) { try { Cipher cipher = Cipher.getInstance("AES/CFB8/NoPadding"); cipher.init(mode, (Key)key, (AlgorithmParameterSpec)(new IvParameterSpec(key.getEncoded())));