• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileOutputStream w/ Cipher adds extra lines unnecessarily

 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code seems prints to "login.encrypted" empty lines, then the value of "x". Does this do this on it's own or is another part of my 1.2k + lined program that is buggy?


Thanks,
John Price
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried your code, and I've got this content in the output file:

It seems to be encrypted, I don't see any empty lines in it.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I read the file back in, I see the empty lines. With CipherInputStream and a BufferedReader. I use this over my program in other places and don't see this issue until after it is written to, adding a line to the end (which adds the blank lines for some reason).

Thanks,
cc11rocks
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But that is an entirely different question. Now you are saying that encryption followed by decryption causes extra lines to be added. Obviously there is the possibility that the decryption process is the problem. At any rate I'm sure the answer is that some part of your program is buggy.

However you don't have to debug 1200 lines of code. You just have to extract the encrypting and decrypting parts and put them into a 50-line test program.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the read in where the lines display extra lines. Note this does not happen if something hasn't been appended to the file.


Output gives somthing like this :


If I put in a test case, I get this :


Which displays this :


Thanks,
John Price
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john price wrote:Here is the read in where the lines display extra lines. Note this does not happen if something hasn't been appended to the file.


Something is appended to the encrypted file ?
Does it mean, that something unencrypted has been appended to encrypted contents ?
If yes, then the problem is here - the encrypted file doesn't have
neither information of the content's size nor any checksum. The cipher doesn't detect the end of the encrypted output,
and it doesn't detect if contents has been modified.
It dencrypts the whole content - if something is appended to it,
it decrypts this part too.



 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to append to the whole file. I was adding encrypted information to the file. I had to release the next version of a program so this is no longer a problem. I used a more efficient way by rewriting the whole file and adding the specific item to memory. Thanks for your help.

John Price
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!