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
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionChunkedCipherOutputStream(OutputStream stream, int chunkSize) ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidcalculateChecksum(File fileOut, int oleStreamSize) voidclose()protected abstract voidcreateEncryptionInfoEntry(DirectoryNode dir, File tmpFile) protected byte[]getChunk()protected intprotected BitSetprotected longgetPos()protected longfinal CipherinitCipherForBlock(int block, boolean lastChunk) protected abstract CipherinitCipherForBlock(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) Methods inherited from class java.io.FilterOutputStream
flushMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
ChunkedCipherOutputStream
public ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
ChunkedCipherOutputStream
public ChunkedCipherOutputStream(OutputStream stream, int chunkSize) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
-
Method Details
-
initCipherForBlock
public final Cipher initCipherForBlock(int block, boolean lastChunk) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
initCipherForBlock
protected abstract Cipher initCipherForBlock(Cipher existing, int block, boolean lastChunk) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
calculateChecksum
protected abstract void calculateChecksum(File fileOut, int oleStreamSize) throws GeneralSecurityException, IOException - Throws:
GeneralSecurityExceptionIOException
-
createEncryptionInfoEntry
protected abstract void createEncryptionInfoEntry(DirectoryNode dir, File tmpFile) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
writePlain
- Throws:
IOException
-
write
- Throws:
IOException
-
getChunkMask
protected int getChunkMask() -
writeChunk
- Throws:
IOException
-
invokeCipher
Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses it's own implementation -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-
getChunk
protected byte[] getChunk() -
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
-