Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

Although I have read some posts I didnt have manage to solve my issue!

I am trying to make a client server application with symmetric encryption. So here is what I do.

This is my while from my server

 while ((inputLine = in.readLine()) != null) {
        AES_Cipher.init (Cipher.DECRYPT_MODE, AES_Key);


plaintext_decrypted = AES_Cipher.doFinal (inputLine.getBytes("UTF-8"));

        System.out.println("Server receive : "+ plaintext_decrypted);
        System.out.println("type message :");
        outputLine = stdIn.readLine();
        out.println(outputLine);
    }

Before I put this line plaintext_decrypted = AES_Cipher.doFinal (inputLine.getBytes("UTF-8"));

Everything works. But when I try to decrypt my message it crushes :/

share|improve this question

1 Answer 1

  1. Read bytes, not lines. There are no lines in cipher text.
  2. Move the cipher init ahead of the read loop. You don't want to re initialize it every time around the loop.
  3. Don't use doFinal(), use update(), assuming the sender did the same, which is rather likely.
share|improve this answer
    
I use this "BufferedReader in = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()));" to read from socket. I cant read bytes with this so I guess I have to change this one. I used update() instead of doFinal() but it didnt worked still crushes :/ Anyway thank you for your help :) – Hayate Osinu Jun 1 at 16:43
    
This is my 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) – Hayate Osinu Jun 1 at 18:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.