Package org.apache.poi.poifs.crypt
Class ChunkedCipherInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.poi.util.LittleEndianInputStream
org.apache.poi.poifs.crypt.ChunkedCipherInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
,LittleEndianInput
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionChunkedCipherInputStream
(InputStream stream, long size, int chunkSize) ChunkedCipherInputStream
(InputStream stream, long size, int chunkSize, int initialPos) -
Method Summary
Modifier and TypeMethodDescriptionint
protected byte[]
getChunk()
protected int
protected byte[]
getPlain()
long
getPos()
final Cipher
initCipherForBlock
(int block) protected abstract Cipher
initCipherForBlock
(Cipher existing, int block) protected int
invokeCipher
(int totalBytes, boolean doFinal) Helper function for overriding the cipher invocation, i.e.void
mark
(int readlimit) boolean
int
read()
int
read
(byte[] b, int off, int len) void
readPlain
(byte[] b, int off, int len) Used when BIFF header fields (sid, size) are being read.void
reset()
void
setNextRecordSize
(int recordSize) Some ciphers (actually just XOR) are based on the record size, which needs to be set before decryptionlong
skip
(long n) Methods inherited from class org.apache.poi.util.LittleEndianInputStream
readByte, readDouble, readFully, readFully, readInt, readLong, readShort, readUByte, readUInt, readUShort
Methods inherited from class java.io.FilterInputStream
close, read
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
ChunkedCipherInputStream
public ChunkedCipherInputStream(InputStream stream, long size, int chunkSize) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
ChunkedCipherInputStream
public ChunkedCipherInputStream(InputStream stream, long size, int chunkSize, int initialPos) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
-
Method Details
-
initCipherForBlock
- Throws:
IOException
GeneralSecurityException
-
initCipherForBlock
protected abstract Cipher initCipherForBlock(Cipher existing, int block) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
skip
public long skip(long n) - Overrides:
skip
in classFilterInputStream
-
available
public int available()- Specified by:
available
in interfaceLittleEndianInput
- Overrides:
available
in classLittleEndianInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classFilterInputStream
-
mark
public void mark(int readlimit) - Overrides:
mark
in classFilterInputStream
-
reset
public void reset()- Overrides:
reset
in classFilterInputStream
-
getChunkMask
protected int getChunkMask() -
invokeCipher
Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses it's own implementation- Throws:
GeneralSecurityException
-
readPlain
public void readPlain(byte[] b, int off, int len) Used when BIFF header fields (sid, size) are being read. The internalCipher
instance must step even when unencrypted bytes are read- Specified by:
readPlain
in interfaceLittleEndianInput
- Overrides:
readPlain
in classLittleEndianInputStream
- Parameters:
b
- the byte array to receive the bytesoff
- the start offset into the byte arraylen
- the amount of bytes to fill
-
setNextRecordSize
public void setNextRecordSize(int recordSize) Some ciphers (actually just XOR) are based on the record size, which needs to be set before decryption- Parameters:
recordSize
- the size of the next record
-
getChunk
protected byte[] getChunk()- Returns:
- the chunk bytes
-
getPlain
protected byte[] getPlain()- Returns:
- the plain bytes
-
getPos
public long getPos()- Returns:
- the absolute position in the stream
-