• Post Reply Bookmark Topic Watch Topic
  • New Topic

Size of encrypted byte array  RSS feed

 
S Thanigaivel
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I transfer an encrypted array of bytes thourgh UDP. The size of byte array that I send varies during every transaction.

=========
byte [] buffer1 = DES.encode(datatotransfer,secretkey);
sock.send(new DatagramPacket(buffer1, offset, buffer1.length, addr, port));
=========

I face problem when I receive this data.

==========
DatagramPacket p = new DatagramPacket(buffer1, offset, 2048, addr, port);
sock.receive(p);
buffer = DES.decode(buffer1,secretkey);
==========

As i am fixing the length to 2048, I get "BadPaddingException" when I try to decrypt the byte stream.

Is there any way through which I can know the size of the incoming stream?
Alternately, can I transfer a fixed 2048 bytes every time, using some padding techniques?
 
Grant Gainey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DatagramPacket.length() should tell you the "actual" length of the data in the packet. Haven't done UDP in a Very Long Time - but I suspect you're handing DES lots of zero-bytes after the real end of your message. En/decryption is length-sensitive - no algorithm is going to like that.

Try using cipher.decode(buffer1, 0, p.getLength()) and see if that helps.

Grant
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!