@NotThreadSafe 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).
CipherReadOnlyFile| Modifier and Type | Field and Description |
|---|---|
protected org.bouncycastle.crypto.BufferedBlockCipher |
cipher
The buffered block cipher used for preprocessing the output.
|
delegate| Constructor and Description |
|---|
CipherOutputStream(OutputStream out,
org.bouncycastle.crypto.BufferedBlockCipher cipher)
Creates a new cipher output stream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this output stream and releases any resources associated with it.
|
protected void |
finish()
Finishes and voids this cipher output stream.
|
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 org.bouncycastle.crypto.BufferedBlockCipher cipher
@CreatesObligation public CipherOutputStream(@CheckForNull@WillCloseWhenClosed OutputStream out, @CheckForNull org.bouncycastle.crypto.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 for subsequent initialization by a sub-class.cipher - The cipher to use for encryption or decryption.
Maybe null for subsequent initialization by a sub-class.public void close()
throws IOException
finish() gets called and
cipher gets set to null upon success.
Next, the DecoratingOutputStream.delegate gets unconditionally
closed.close in interface Closeableclose in interface AutoCloseableclose in class DecoratingOutputStreamIOException - On any I/O failure.@OverridingMethodsMustInvokeSuper protected void finish() throws IOException
Note that after a call to this method only close() may get
called on this cipher output stream
The result of calling any other method (including this one) is undefined!
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 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 of the data in the 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 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.Copyright © 2005-2013 Schlichtherle IT Services. All Rights Reserved.