• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java symmetric encryption - server crushes

 
mpampis Osirou
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I am trying to make a java client-server application with symmetric encryption!! But I got this error!

This is my while from my server


Before I put this line
Everything works. But when I try to decrypt my message the server crushes :/

This is the error
Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at Client.main(Client.java:58)


Could someone help me ?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By reading lines it looks to me like your are treating ciphertext bytes as characters which they are not. Bytes are not characters and Character streams cannot reliably be used to read binary data and ciphertext is most definitely not characters without first using something like Base64 or HEX encoding which you do not seem to be doing. Also, even if you change to using byte streams rather than character streams you cannot use doFinal() on a fragment of the input. You need to use update() on each fragment and then doFinal() when the input is complete. Also, you need to use AES as a stream cipher (yes it is possible to use a block cipher as a stream cipher) and not as a block cipher.
 
mpampis Osirou
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks bro I understand it now ;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!