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 intavailable()protected byte[]getChunk()protected intgetChunkMask()protected byte[]getPlain()longgetPos()CipherinitCipherForBlock(int block)protected abstract CipherinitCipherForBlock(Cipher existing, int block)protected intinvokeCipher(int totalBytes, boolean doFinal)Helper function for overriding the cipher invocation, i.e.voidmark(int readlimit)booleanmarkSupported()intread()intread(byte[] b, int off, int len)voidreadPlain(byte[] b, int off, int len)Used when BIFF header fields (sid, size) are being read.voidreset()voidsetNextRecordSize(int recordSize)Some ciphers (actually just XOR) are based on the record size, which needs to be set before decryptionlongskip(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:
IOExceptionGeneralSecurityException
-
initCipherForBlock
protected abstract Cipher initCipherForBlock(Cipher existing, int block) throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
read
public int read() throws IOException- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classLittleEndianInputStream- Throws:
IOException
-
skip
public long skip(long n)
- Overrides:
skipin classFilterInputStream
-
available
public int available()
- Specified by:
availablein interfaceLittleEndianInput- Overrides:
availablein classLittleEndianInputStream
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classFilterInputStream
-
mark
public void mark(int readlimit)
- Overrides:
markin classLittleEndianInputStream
-
reset
public void reset()
- Overrides:
resetin classLittleEndianInputStream
-
getChunkMask
protected int getChunkMask()
-
invokeCipher
protected int invokeCipher(int totalBytes, boolean doFinal) throws GeneralSecurityExceptionHelper 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 internalCipherinstance must step even when unencrypted bytes are read- Specified by:
readPlainin interfaceLittleEndianInput- Overrides:
readPlainin 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
-
-