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 TypeMethodDescriptionintprotected byte[]getChunk()protected intprotected byte[]getPlain()longgetPos()final 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) booleanintread()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
readByte, readDouble, readFully, readFully, readInt, readLong, readShort, readUByte, readUInt, readUShortMethods inherited from class java.io.FilterInputStream
close, readMethods 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:
IOExceptionGeneralSecurityException
-
initCipherForBlock
protected abstract Cipher initCipherForBlock(Cipher existing, int block) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
- Overrides:
readin classFilterInputStream- 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 classFilterInputStream
-
reset
public void reset()- Overrides:
resetin 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 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
-