| Author |
sending an encrypted byte array through a socket
|
Alessandro Brawerman
Greenhorn
Joined: Sep 22, 2003
Posts: 22
|
|
Hi all, I'm trying to send an encrypted byte array through a socket. The other side (the client) has to read it and decrypt it. The problem is that the client is not receiving the encrypted byte array correct. Below follows the code I have: ---- sending the encrypted byte array (server side) byte[] data = "test".getBytes(); byte[] result = cipher1.doFinal(data); BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream()); bos.write(result); bos.flush(); ----- receiving the encrypted byte array (client side) BufferedInputStream bin = new BufferedInputStream(connection.getInputStream()); byte[] input = new byte[64]; for(int i = 0; i < input.length; i++) { int b = bin.read(); if(b == -1) break; input[i] = (byte) b; } When I check if input is equal to result, I get a no as answer. Is anything wrong with my code? Thanks a lot. Alessandro.
|
 |
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
|
|
When you decrypt the received bytes, do you decrypt the entire array of 64 bytes? If so, you're adding a bunch of zeros that weren't in the original cyphertext. If not that, did you compare the two byte arrays to see if you at least received the correct bytes?
|
 |
Kumar
Greenhorn
Joined: Apr 13, 2005
Posts: 4
|
|
|
You can use in.readFully...
|
 |
 |
|
|
subject: sending an encrypted byte array through a socket
|
|
|