Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

help with "socket programming and AES"

807603Jan 28 2008 — edited Jan 28 2008
hello people.

i've got the code for AES off one of sun's developer articles. it works fine when it's standalone.. here's the background and the problem(s).

i'm doing socket programming, passing encrypted messages back and forth "client" and "server". unfortunately, only some "ciphertexts" can be decrypted, others would return with "javax.crypto.BadPaddingException: Given final block not properly padded" or "javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher". i've made some System.out.prints to retrieve the "byte" ciphertext and "hex" ciphertext, and some of the "byte" ciphertexts have 0 appended infront. Then again, some that looks exactly the same, work on the standalone but not via the socket.

i'm using DataInputStream to send and receive data, and so i used the asHex function to convert the byte[] to a String so that the ciphertext can be sent to and fro. i've another function hexToByte to convert the String back to byte[] for decryption on the other end.

questions... am i using the wrong kind of IO? i'm puzzled as to why it works on the standalone but not on my program.

eg of the "byte[]" ciphertext - 45-342413-8233-60-444310882-46-61-107-40-29121-2133-732363-120-528654-40-808924-42
eg of the "hex" ciphertext - 2dde180dae21c4d42b6c52d2c395fc00e379eb21b7173f88cc5636d8b05918d6
They are results of the same
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 25 2008
Added on Jan 28 2008
8 comments
269 views