Class CipherOutputStream
java.lang.Object
java.io.OutputStream
tech.oxfordsemantic.jrdfox.io.CipherOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
A class which wraps an output stream, encrypting the data written to it using AES-256-CBC. The output stream
is provided data in the following format:
Initialization vector (16 bytes) followed by a sequence of encrypted blocks. Each encrypted block is preceded by
8 bytes which are to be interpreted as an unsigned integer in little-endian encoding. The integer denotes the size
(in bytes) of the data within the block (before padding is applied). The data within the block is padded to the
next multiple of the cipher block size and encrypted using AES-256-CBC.
-
Constructor Summary
ConstructorsConstructorDescriptionCipherOutputStream(OutputStream outputStream) Creates a new CipherOutputStream object to encrypt the data before passing it into the provided output stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Flushes, then closes the output stream.voidflush()Flushes the output stream.voidinitialize(Key key) Initializes the cipher with the provided key and writes the initialization vector to the output stream.voidwrite(byte[] data, int dataOffset, int numberOfBytesToWrite) Writes the specified byte array to the output stream.voidwrite(int b) Writes the specified byte to the output stream.Methods inherited from class OutputStream
nullOutputStream, write
-
Constructor Details
-
CipherOutputStream
Creates a new CipherOutputStream object to encrypt the data before passing it into the provided output stream.- Parameters:
outputStream- the output stream to which the data will be written- Throws:
IOException- if an I/O error occurs
-
-
Method Details
-
initialize
Initializes the cipher with the provided key and writes the initialization vector to the output stream.- Parameters:
key- the key to be used for encryption- Throws:
InvalidKeyException- if the key is invalidIOException- if an I/O error occurs
-
write
Writes the specified byte to the output stream.- Specified by:
writein classOutputStream- Parameters:
b- the byte to be written- Throws:
IOException- if an I/O error occurs
-
write
Writes the specified byte array to the output stream.- Overrides:
writein classOutputStream- Parameters:
data- the byte array to be writtendataOffset- the start offset in the data arraynumberOfBytesToWrite- the number of bytes to write- Throws:
IOException- if an I/O error occurs
-
flush
Flushes the output stream.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException- if an I/O error occurs
-
close
Flushes, then closes the output stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException- if an I/O error occurs
-