Class PositionedCryptoInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.crypto.stream.CryptoInputStream
org.apache.commons.crypto.stream.CtrCryptoInputStream
org.apache.commons.crypto.stream.PositionedCryptoInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ReadableByteChannel
PositionedCryptoInputStream provides the capability to decrypt the stream
starting at random position as well as provides the foundation for positioned
read for decrypting. This needs a stream cipher mode such as AES CTR mode.
-
Field Summary
Fields inherited from class CryptoInputStream
EOS, STREAM_BUFFER_SIZE_KEY -
Constructor Summary
ConstructorsModifierConstructorDescriptionPositionedCryptoInputStream(Properties properties, Input in, byte[] key, byte[] iv, long streamOffset) Constructs aPositionedCryptoInputStream.protectedPositionedCryptoInputStream(Properties properties, Input input, CryptoCipher cipher, int bufferSize, byte[] key, byte[] iv, long streamOffset) Constructs aPositionedCryptoInputStream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Overrides theCryptoInputStream.close().protected voiddecrypt(long position, byte[] buffer, int offset, int length) Decrypts length bytes in buffer starting at offset.intread(long position, byte[] buffer, int offset, int length) Reads up to the specified number of bytes from a given position within a stream and return the number of bytes read.voidreadFully(long position, byte[] buffer) Reads the specified number of bytes from a given position within a stream.voidreadFully(long position, byte[] buffer, int offset, int length) Reads the specified number of bytes from a given position within a stream.Methods inherited from class CtrCryptoInputStream
decrypt, decrypt, decryptBuffer, decryptInPlace, decryptMore, getCounter, getInitIV, getPadding, getStreamOffset, getStreamPosition, initCipher, postDecryption, read, resetCipher, resetStreamOffset, seek, setStreamOffset, skipMethods inherited from class CryptoInputStream
available, checkStream, decryptFinal, freeBuffers, getBufferSize, getCipher, getInput, getKey, getParams, isOpen, markSupported, read, readMethods inherited from class InputStream
mark, read, reset
-
Constructor Details
-
PositionedCryptoInputStream
public PositionedCryptoInputStream(Properties properties, Input in, byte[] key, byte[] iv, long streamOffset) throws IOException Constructs aPositionedCryptoInputStream.- Parameters:
properties- ThePropertiesclass represents a set of properties.in- the input data.key- crypto key for the cipher.iv- Initialization vector for the cipher.streamOffset- the start offset in the data.- Throws:
IOException- if an I/O error occurs.
-
PositionedCryptoInputStream
protected PositionedCryptoInputStream(Properties properties, Input input, CryptoCipher cipher, int bufferSize, byte[] key, byte[] iv, long streamOffset) throws IOException Constructs aPositionedCryptoInputStream.- Parameters:
properties- the properties of streaminput- the input data.cipher- the CryptoCipher instance.bufferSize- the bufferSize.key- crypto key for the cipher.iv- Initialization vector for the cipher.streamOffset- the start offset in the data.- Throws:
IOException- if an I/O error occurs.
-
-
Method Details
-
close
Overrides theCryptoInputStream.close(). Closes this input stream and releases any system resources associated with the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Overrides:
closein classCryptoInputStream- Throws:
IOException- if an I/O error occurs.
-
decrypt
Decrypts length bytes in buffer starting at offset. Output is also put into buffer starting at offset. It is thread-safe.- Parameters:
position- the offset from the start of the stream.buffer- the buffer into which the data is read.offset- the start offset in the data.length- the maximum number of bytes to read.- Throws:
IOException- if an I/O error occurs.
-
read
Reads up to the specified number of bytes from a given position within a stream and return the number of bytes read. This does not change the current offset of the stream, and is thread-safe.- Parameters:
position- the offset from the start of the stream.buffer- the buffer into which the data is read.offset- the start offset in the data.length- the maximum number of bytes to read.- Returns:
- int the total number of decrypted data bytes read into the buffer.
- Throws:
IOException- if an I/O error occurs.
-
readFully
Reads the specified number of bytes from a given position within a stream. This does not change the current offset of the stream and is thread-safe.- Parameters:
position- the offset from the start of the stream.buffer- the buffer into which the data is read.- Throws:
IOException- if an I/O error occurs.
-
readFully
Reads the specified number of bytes from a given position within a stream. This does not change the current offset of the stream and is thread-safe.- Parameters:
position- the offset from the start of the stream.buffer- the buffer into which the data is read.offset- the start offset in the data.length- the maximum number of bytes to read.- Throws:
IOException- if an I/O error occurs.
-