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
@Internal public abstract class ChunkedCipherInputStream extends LittleEndianInputStream
-
-
Field Summary
-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description ChunkedCipherInputStream(InputStream stream, long size, int chunkSize)
ChunkedCipherInputStream(InputStream stream, long size, int chunkSize, int initialPos)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
available()
protected byte[]
getChunk()
protected int
getChunkMask()
protected byte[]
getPlain()
long
getPos()
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
markSupported()
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
getReadIndex, readByte, readDouble, readFloat, readFully, readFully, readInt, readLong, readShort, readUByte, readUInt, readUShort, skipFully
-
Methods inherited from class java.io.FilterInputStream
close, read
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
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 Detail
-
initCipherForBlock
public final Cipher initCipherForBlock(int block) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
initCipherForBlock
protected abstract Cipher initCipherForBlock(Cipher existing, int block) throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
read
public int read() throws IOException
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classLittleEndianInputStream
- 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 classLittleEndianInputStream
-
reset
public void reset()
- Overrides:
reset
in classLittleEndianInputStream
-
getChunkMask
protected int getChunkMask()
-
invokeCipher
protected int invokeCipher(int totalBytes, boolean doFinal) throws GeneralSecurityException
Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses its 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
-
-