I think the problem may be that the encryption reads it line by line, and encrypts the line - bu in the new encrypted line, it could have introduced new newline characters by accident. These newline characters are not decrypted as they should, because the decryption also reads line by lines, and doesn't see the difference between these new newlines and the ones that were supposed to be newlines in the original file.
I could be wrong, but it's my best guess.
Maybe adding the lines of the file to one big string, and using that for encryption/decryption would work better.
Edit : here's an example of what I mean :
This could be the input
line 1 : content of line1
line 2 : content of line2
line 3 : content of line3
But encrypting could lead to :
line 1 : encrypted line1
line 2 : encrypted line2 - part 1
line 3 : encrypted line2 - part 2
line 4 : encrypted line3
now decrypting would read each line seperately and would lead to :
line 1 : content of line1
line 2 : part of the content of line2
line 3 : part of the content of line2
line 4 : content of line3
Then again, I could be wrong :)
I could be wrong, but it's my best guess.
Maybe adding the lines of the file to one big string, and using that for encryption/decryption would work better.
Edit : here's an example of what I mean :
This could be the input
line 1 : content of line1
line 2 : content of line2
line 3 : content of line3
But encrypting could lead to :
line 1 : encrypted line1
line 2 : encrypted line2 - part 1
line 3 : encrypted line2 - part 2
line 4 : encrypted line3
now decrypting would read each line seperately and would lead to :
line 1 : content of line1
line 2 : part of the content of line2
line 3 : part of the content of line2
line 4 : content of line3
Then again, I could be wrong :)