@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) public class CipherOutputStream extends DecoratingOutputStream
javax.crypto.CipherOutputStream,
with some exceptions:
BufferedBlockCipher for ciphering.
cipher used for encryption or decryption is accessible to
subclasses.
flush() method just flushes the underlying output stream
and has no effect on the cipher.
finish() method has been added to allow finishing the output
(probably producing padding bytes) without closing the output.
This could be used in a subclass to produce a trailer with additional
information about the ciphered data (e.g. a MAC).
| Modifier and Type | Field and Description |
|---|---|
protected BufferedBlockCipher |
cipher
The buffered block cipher used for preprocessing the output.
|
private boolean |
closed
Whether this stream has been closed or not.
|
private byte[] |
outBuf
The buffer used for preprocessing the output.
|
delegate| Constructor and Description |
|---|
CipherOutputStream(OutputStream out,
BufferedBlockCipher cipher)
Creates a new instance of CipherOutputStream.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
assertOpen()
Asserts that this cipher output stream is in open state, which requires
that
cipher is not null. |
void |
close()
Closes this output stream and releases any resources associated with it.
|
void |
finish()
Finishes this stream and resets it to it's initial state.
|
void |
write(byte[] buf,
int off,
int len)
Ciphers and writes the contents of the given byte array to the
underlying output stream.
|
void |
write(int b)
Ciphers and writes the given byte to the underlying output stream.
|
flush, toString, write@Nullable protected BufferedBlockCipher cipher
private byte[] outBuf
private boolean closed
public CipherOutputStream(@CheckForNull
OutputStream out,
@CheckForNull
BufferedBlockCipher cipher)
javax.crypto.CipherOutputStream,
the cipher does not need to be initialized before calling this
constructor.
However, the cipher must be initialized before anything is actually
written to this stream or before this stream is closed.out - The output stream to write the encrypted or decrypted data to.
Maybe null if initialized by the subclass constructor.cipher - The cipher to use for encryption or decryption.
Maybe null for subsequent initialization by a subclass.private void assertOpen()
throws IOException
cipher is not null.IOException - If the preconditions do not hold.public void write(int b)
throws IOException
write in class DecoratingOutputStreamb - The byte to cipher and write.IOException - If out or cipher aren't properly initialized,
the stream has been closed or an I/O error occured.public void write(byte[] buf,
int off,
int len)
throws IOException
write in class DecoratingOutputStreambuf - The buffer holding the data to cipher and write.off - The start offset in the data buffer.len - The number of bytes to cipher and write.IOException - If out or cipher aren't properly initialized,
the stream has been closed or an I/O error occured.public void finish()
throws IOException
Please note that subsequent calls to any write operations after this method may cause an error in the output data if padding is used!
IOException - If out or cipher aren't properly initialized,
the stream has been closed, an I/O error occured the cipher
text is invalid, i.e. required padding information is missing.public void close()
throws IOException
finish() and then closes and nullifies
the underlying output stream DecoratingOutputStream.delegate and the cipher
cipher.close in interface Closeableclose in interface AutoCloseableclose in class DecoratingOutputStreamIOException - If an I/O error occurs.Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.