CipherInputStream is Empty when trying to decrypt file

ⅰ亾dé卋堺 提交于 2019-12-04 22:06:32

However, the problem arises when I try to read from an encrypted text file.

There is no such thing as an 'encrypted text file'. The result of encryption is binary, not text.

I can verify that the String I feed it is being encrypted and written to the correct file, but when I try to read back from this file, the BufferedReader reports an EOF (null).

You shouldn't be using a BufferedReader. It isn't text, it is binary. Use a BufferedInputStream.

It didn't matter whether I wrote via a PrintWriter or a BufferedOutputStream, nor whether I read with a Reader or not. Turns out, I forgot to close the OutputStream that created the file. As soon as I added that one little line, everything began working. Thank you to Antoniossss for suggesting I redo the broken part of my method. I wonder why Eclipse didn't mention a resource leak about it...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!