From 3f216378765749ba635448e155882732ed459e68 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Wed, 11 Oct 2023 16:32:57 +0200 Subject: [PATCH] removed a bit of code smell --- .../baseband/server/socket/ClientHandler.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Server/src/main/java/dev/baseband/server/socket/ClientHandler.java b/Server/src/main/java/dev/baseband/server/socket/ClientHandler.java index ae8589e..fb8cfec 100644 --- a/Server/src/main/java/dev/baseband/server/socket/ClientHandler.java +++ b/Server/src/main/java/dev/baseband/server/socket/ClientHandler.java @@ -188,7 +188,7 @@ public class ClientHandler extends Thread { if (result >= 0 || result == -2) { System.out.println("Client is valid"); dos.writeInt(result); - Map, byte[]> data = new HashMap<>(); + HashMap data = new HashMap<>(); try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(SocketHandler.clientFileData))) { ZipEntry zipEntry; @@ -201,21 +201,21 @@ public class ClientHandler extends Thread { bos.write(buffer, 0, len); } bos.close(); - Map dataLocal = new HashMap<>(); - byte[] keyData = SecureRandom.getSeed(256); - dataLocal.put(zipEntry.getName(), new Key(keyData).encryptByte(bos.toByteArray())); - data.put(dataLocal, keyData); + data.put(zipEntry.getName(), bos.toByteArray()); } } dos.writeInt(data.size()); - for (Map.Entry, byte[]> mapEntry : data.entrySet()) { - Map.Entry entry = mapEntry.getKey().entrySet().iterator().next(); + SecureRandom rand = new SecureRandom(); + for (Map.Entry entry : data.entrySet()) { String className = entry.getKey(); //Name byte[] classData = entry.getValue(); //Data - byte[] cryptKey = mapEntry.getValue(); //Key + byte[] cryptKey = new byte[256]; + rand.nextBytes(cryptKey); + Key k = new Key(cryptKey); + classData = k.encryptByte(classData); byte[] encryptedBytes = key.encryptByte(aesE.doFinal(className.getBytes())); dos.writeInt(encryptedBytes.length);