removed a bit of code smell

This commit is contained in:
Daniella / Tove 2023-10-11 16:32:57 +02:00
parent 7f19262325
commit 3f21637876
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -188,7 +188,7 @@ public class ClientHandler extends Thread {
if (result >= 0 || result == -2) { if (result >= 0 || result == -2) {
System.out.println("Client is valid"); System.out.println("Client is valid");
dos.writeInt(result); dos.writeInt(result);
Map<Map<String, byte[]>, byte[]> data = new HashMap<>(); HashMap<String, byte[]> data = new HashMap<>();
try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(SocketHandler.clientFileData))) { try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(SocketHandler.clientFileData))) {
ZipEntry zipEntry; ZipEntry zipEntry;
@ -201,21 +201,21 @@ public class ClientHandler extends Thread {
bos.write(buffer, 0, len); bos.write(buffer, 0, len);
} }
bos.close(); bos.close();
Map<String, byte[]> dataLocal = new HashMap<>(); data.put(zipEntry.getName(), bos.toByteArray());
byte[] keyData = SecureRandom.getSeed(256);
dataLocal.put(zipEntry.getName(), new Key(keyData).encryptByte(bos.toByteArray()));
data.put(dataLocal, keyData);
} }
} }
dos.writeInt(data.size()); dos.writeInt(data.size());
for (Map.Entry<Map<String, byte[]>, byte[]> mapEntry : data.entrySet()) { SecureRandom rand = new SecureRandom();
Map.Entry<String, byte[]> entry = mapEntry.getKey().entrySet().iterator().next();
for (Map.Entry<String, byte[]> entry : data.entrySet()) {
String className = entry.getKey(); //Name String className = entry.getKey(); //Name
byte[] classData = entry.getValue(); //Data 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())); byte[] encryptedBytes = key.encryptByte(aesE.doFinal(className.getBytes()));
dos.writeInt(encryptedBytes.length); dos.writeInt(encryptedBytes.length);