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:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
- Direct Known Subclasses:
BinaryRC4Encryptor.BinaryRC4CipherOutputStream,CryptoAPIEncryptor.CryptoAPICipherOutputStream
@Internal public abstract class ChunkedCipherOutputStream extends java.io.FilterOutputStream
-
-
Constructor Summary
Constructors Constructor Description ChunkedCipherOutputStream(java.io.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 voidcalculateChecksum(java.io.File fileOut, int oleStreamSize)voidclose()protected abstract voidcreateEncryptionInfoEntry(DirectoryNode dir, java.io.File tmpFile)protected byte[]getChunk()protected intgetChunkMask()protected com.zaxxer.sparsebits.SparseBitSetgetPlainByteFlags()protected longgetPos()protected longgetTotalPos()javax.crypto.CipherinitCipherForBlock(int block, boolean lastChunk)protected abstract javax.crypto.CipherinitCipherForBlock(javax.crypto.Cipher existing, int block, boolean lastChunk)protected javax.crypto.CipherinitCipherForBlockNoFlush(javax.crypto.Cipher existing, int block, boolean lastChunk)protected intinvokeCipher(int posInChunk, boolean doFinal)Helper function for overriding the cipher invocation, i.e.voidsetNextRecordSize(int recordSize, boolean isPlain)Some ciphers (actually just XOR) are based on the record size, which needs to be set before encryptionvoidwrite(byte[] b)voidwrite(byte[] b, int off, int len)protected voidwrite(byte[] b, int off, int len, boolean writePlain)voidwrite(int b)protected voidwriteChunk(boolean continued)voidwritePlain(byte[] b, int off, int len)
-
-
-
Constructor Detail
-
ChunkedCipherOutputStream
public ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
ChunkedCipherOutputStream
public ChunkedCipherOutputStream(java.io.OutputStream stream, int chunkSize) throws java.io.IOException, java.security.GeneralSecurityException- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
-
Method Detail
-
initCipherForBlock
public final javax.crypto.Cipher initCipherForBlock(int block, boolean lastChunk) throws java.io.IOException, java.security.GeneralSecurityException- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
initCipherForBlockNoFlush
@Internal protected javax.crypto.Cipher initCipherForBlockNoFlush(javax.crypto.Cipher existing, int block, boolean lastChunk) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
initCipherForBlock
protected abstract javax.crypto.Cipher initCipherForBlock(javax.crypto.Cipher existing, int block, boolean lastChunk) throws java.io.IOException, java.security.GeneralSecurityException- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
calculateChecksum
protected abstract void calculateChecksum(java.io.File fileOut, int oleStreamSize) throws java.security.GeneralSecurityException, java.io.IOException- Throws:
java.security.GeneralSecurityExceptionjava.io.IOException
-
createEncryptionInfoEntry
protected abstract void createEncryptionInfoEntry(DirectoryNode dir, java.io.File tmpFile) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
write
public void write(int b) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
writePlain
public void writePlain(byte[] b, int off, int len) throws java.io.IOException- Throws:
java.io.IOException
-
write
protected void write(byte[] b, int off, int len, boolean writePlain) throws java.io.IOException- Throws:
java.io.IOException
-
getChunkMask
protected int getChunkMask()
-
writeChunk
protected void writeChunk(boolean continued) throws java.io.IOException- Throws:
java.io.IOException
-
invokeCipher
protected int invokeCipher(int posInChunk, boolean doFinal) throws java.security.GeneralSecurityException, java.io.IOExceptionHelper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses its own implementation- Throws:
java.security.GeneralSecurityExceptionjava.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterOutputStream- Throws:
java.io.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-trueif the record is unencrypted
-
-