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:
- java.io.Closeable, LittleEndianInput
@Internal
public abstract class ChunkedCipherInputStream
- extends LittleEndianInputStream
Fields inherited from class java.io.FilterInputStream |
in |
Method Summary |
int |
available()
|
protected byte[] |
getChunk()
|
protected int |
getChunkMask()
|
protected byte[] |
getPlain()
|
long |
getPos()
|
protected abstract javax.crypto.Cipher |
initCipherForBlock(javax.crypto.Cipher existing,
int block)
|
javax.crypto.Cipher |
initCipherForBlock(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 decryption |
long |
skip(long n)
|
Methods inherited from class java.io.FilterInputStream |
close, read |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ChunkedCipherInputStream
public ChunkedCipherInputStream(java.io.InputStream stream,
long size,
int chunkSize)
throws java.security.GeneralSecurityException
- Throws:
java.security.GeneralSecurityException
ChunkedCipherInputStream
public ChunkedCipherInputStream(java.io.InputStream stream,
long size,
int chunkSize,
int initialPos)
throws java.security.GeneralSecurityException
- Throws:
java.security.GeneralSecurityException
initCipherForBlock
public final javax.crypto.Cipher initCipherForBlock(int block)
throws java.io.IOException,
java.security.GeneralSecurityException
- Throws:
java.io.IOException
java.security.GeneralSecurityException
initCipherForBlock
protected abstract javax.crypto.Cipher initCipherForBlock(javax.crypto.Cipher existing,
int block)
throws java.security.GeneralSecurityException
- Throws:
java.security.GeneralSecurityException
read
public int read()
throws java.io.IOException
- Overrides:
read
in class java.io.FilterInputStream
- Throws:
java.io.IOException
read
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
- Overrides:
read
in class java.io.FilterInputStream
- Throws:
java.io.IOException
skip
public long skip(long n)
throws java.io.IOException
- Overrides:
skip
in class java.io.FilterInputStream
- Throws:
java.io.IOException
available
public int available()
- Specified by:
available
in interface LittleEndianInput
- Overrides:
available
in class LittleEndianInputStream
markSupported
public boolean markSupported()
- Overrides:
markSupported
in class java.io.FilterInputStream
mark
public void mark(int readlimit)
- Overrides:
mark
in class java.io.FilterInputStream
reset
public void reset()
throws java.io.IOException
- Overrides:
reset
in class java.io.FilterInputStream
- Throws:
java.io.IOException
getChunkMask
protected int getChunkMask()
invokeCipher
protected int invokeCipher(int totalBytes,
boolean doFinal)
throws java.security.GeneralSecurityException
- Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher
and uses it's own implementation
- Throws:
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
javax.crypto.ShortBufferException
java.security.GeneralSecurityException
readPlain
public void readPlain(byte[] b,
int off,
int len)
- Used when BIFF header fields (sid, size) are being read. The internal
Cipher
instance must step even when unencrypted bytes are read
- Specified by:
readPlain
in interface LittleEndianInput
- Overrides:
readPlain
in class LittleEndianInputStream
- 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