如何强制CipherOutputStream完成加密,但是将基础流打开? [英] How can I force a CipherOutputStream to finish encrypting but leave the underlying stream open?
问题描述
CipherOutputStream的文档表示调用 flush )
不会强制加密器中的最后一个块;因为我需要调用 close()
。但是, close()
也关闭了底层的OutputStream,我仍然需要写更多。
强制最后一个区块加密,不关闭流?我需要编写自己的NonClosingCipherOutputStream吗?
如果您没有参考密码
,您可以将 FilterOutputStream
传递给创建 CipherOutputStream
的方法。在 FilterOutputStream
中,覆盖关闭
方法,使其不会实际关闭流。
I have a CipherOutputStream backed by another OutputStream. After I have finished writing all the data I need encrypted to the CipherOutputStream, I need to append some unencrypted data.
The documentation for CipherOutputStream says that calling flush()
will not force the final block out of the encryptor; for that I need to call close()
. But close()
also closes the underlying OutputStream, which I still need to write more to.
How can I force the last block out of the encryptor without closing the stream? Do I need to write my own NonClosingCipherOutputStream?
If you don't have a reference to the Cipher
, you could pass a FilterOutputStream
to the method that creates the CipherOutputStream
. In the FilterOutputStream
, override the close
method so that it doesn't actually close the stream.
这篇关于如何强制CipherOutputStream完成加密,但是将基础流打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!