(These are just the relevant snippets from my program for my question. out and in are the socket streams, im sure you can see what the rest is)
This snippet here is for the client to send the file to the server, encrypted..
and the server decrypting the file and putting it together on the server..Code:Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); // Send file FileInputStream fin = new FileInputStream(file); byte[] buffer = new byte[8192]; byte[] bout = null; int length; while (true) { length = fin.read(buffer); out.writeInt(length); if (length == -1) break; bout = cipher.update(buffer, 0, length); out.write(bout); }
Everything works fine, except 1 problem. On the client side, say i want to send test.txt and test.txt contains this:Code:Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKey); // receive file FileOutputStream fout = new FileOutputStream(file); byte[] buffer = new byte[8192]; byte[] bout = null; int length; while (true) { length = in.readInt(); if (length <= 0) break; in.read(buffer, 0, length); bout = cipher.update(buffer, 0, length); fout.write(bout); }
on the server side, the file ends up like thisCode:Hello there whats up Multi line test stuff!!
on the last line, it should say: Multi line test stuff!!Code:Hello there whats up Multi line
anyone see what im doing wrong?


Reply With Quote
CornedBee