• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

sending an encrypted byte array through the net

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
OutputStream os = connection.getOutputStream();
os.write(result);
os.flush();
----- receiving the encrypted byte array (client side)
InputStream bin = 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.
 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could it be because the result is longer than 64 bytes?
 
BWA HA HA HA HA HA HA! Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic