Package org.apache.poi.poifs.crypt
Class ChunkedCipherOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- org.apache.poi.poifs.crypt.ChunkedCipherOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
- Direct Known Subclasses:
BinaryRC4Encryptor.BinaryRC4CipherOutputStream
,CryptoAPIEncryptor.CryptoAPICipherOutputStream
@Internal public abstract class ChunkedCipherOutputStream extends FilterOutputStream
-
-
Field Summary
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description ChunkedCipherOutputStream(OutputStream stream, int chunkSize)
ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
calculateChecksum(File fileOut, int oleStreamSize)
void
close()
protected abstract void
createEncryptionInfoEntry(DirectoryNode dir, File tmpFile)
protected byte[]
getChunk()
protected int
getChunkMask()
protected com.zaxxer.sparsebits.SparseBitSet
getPlainByteFlags()
protected long
getPos()
protected long
getTotalPos()
Cipher
initCipherForBlock(int block, boolean lastChunk)
protected abstract Cipher
initCipherForBlock(Cipher existing, int block, boolean lastChunk)
protected Cipher
initCipherForBlockNoFlush(Cipher existing, int block, boolean lastChunk)
protected int
invokeCipher(int posInChunk, boolean doFinal)
Helper function for overriding the cipher invocation, i.e.void
setNextRecordSize(int recordSize, boolean isPlain)
Some ciphers (actually just XOR) are based on the record size, which needs to be set before encryptionvoid
write(byte[] b)
void
write(byte[] b, int off, int len)
protected void
write(byte[] b, int off, int len, boolean writePlain)
void
write(int b)
protected void
writeChunk(boolean continued)
void
writePlain(byte[] b, int off, int len)
-
Methods inherited from class java.io.FilterOutputStream
flush
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
ChunkedCipherOutputStream
public ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
ChunkedCipherOutputStream
public ChunkedCipherOutputStream(OutputStream stream, int chunkSize) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
-
Method Detail
-
initCipherForBlock
public final Cipher initCipherForBlock(int block, boolean lastChunk) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
initCipherForBlockNoFlush
@Internal protected Cipher initCipherForBlockNoFlush(Cipher existing, int block, boolean lastChunk) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
initCipherForBlock
protected abstract Cipher initCipherForBlock(Cipher existing, int block, boolean lastChunk) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
calculateChecksum
protected abstract void calculateChecksum(File fileOut, int oleStreamSize) throws GeneralSecurityException, IOException
- Throws:
GeneralSecurityException
IOException
-
createEncryptionInfoEntry
protected abstract void createEncryptionInfoEntry(DirectoryNode dir, File tmpFile) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
write
public void write(int b) throws IOException
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
write
public void write(byte[] b) throws IOException
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
writePlain
public void writePlain(byte[] b, int off, int len) throws IOException
- Throws:
IOException
-
write
protected void write(byte[] b, int off, int len, boolean writePlain) throws IOException
- Throws:
IOException
-
getChunkMask
protected int getChunkMask()
-
writeChunk
protected void writeChunk(boolean continued) throws IOException
- Throws:
IOException
-
invokeCipher
protected int invokeCipher(int posInChunk, boolean doFinal) throws GeneralSecurityException, IOException
Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses its own implementation- Throws:
GeneralSecurityException
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
-
getChunk
protected byte[] getChunk()
-
getPlainByteFlags
protected com.zaxxer.sparsebits.SparseBitSet getPlainByteFlags()
-
getPos
protected long getPos()
-
getTotalPos
protected long getTotalPos()
-
setNextRecordSize
public void setNextRecordSize(int recordSize, boolean isPlain)
Some ciphers (actually just XOR) are based on the record size, which needs to be set before encryption- Parameters:
recordSize
- the size of the next recordisPlain
-true
if the record is unencrypted
-
-