Top Inners Fields Constructors Methods
org.apache.poi.poifs.crypt.xor

public Class XORDecryptor

extends Decryptor
Class Inheritance
Imports
java.io.IOException, .InputStream, java.security.GeneralSecurityException, javax.crypto.Cipher, .SecretKey, javax.crypto.spec.SecretKeySpec, org.apache.poi.EncryptedDocumentException, org.apache.poi.poifs.crypt.ChunkedCipherInputStream, .CryptoFunctions, .Decryptor, .EncryptionInfo, org.apache.poi.poifs.filesystem.DirectoryNode, org.apache.poi.util.LittleEndian

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private int
private long
Inherited from org.apache.poi.poifs.crypt.Decryptor:
DEFAULT_PASSWORDDEFAULT_POIFS_ENTRYencryptionInfo

Constructor Summary

AccessConstructor and Description
protected
protected

Method Summary

Modifier and TypeMethod and Description
public XORDecryptor
public ChunkedCipherInputStream
getDataStream(DirectoryNode
the node to read from
dir
)

Implements abstract org.apache.poi.poifs.crypt.Decryptor.getDataStream.

Return a stream with decrypted data.

public InputStream
getDataStream(InputStream
the stream to be wrapped
stream
,
int size, int
initial/current byte position within the stream
initialPos
)

Overrides org.apache.poi.poifs.crypt.Decryptor.getDataStream.

Wraps a stream for decryption

As we are handling streams and don't know the total length beforehand, it's the callers duty to care for the length of the entries.

public long
getLength()

Implements abstract org.apache.poi.poifs.crypt.Decryptor.getLength.

Returns the length of the encrypted data that can be safely read with getDataStream(org.apache.poi.poifs.filesystem.DirectoryNode).

public Cipher
initCipherForBlock(Cipher
may be null, otherwise the given instance is reset to the new block index
cipher
,
int
the block index, e.g. the persist/slide id (hslf)
block
)

Overrides org.apache.poi.poifs.crypt.Decryptor.initCipherForBlock.

Initializes a cipher object for a given block index for encryption

protected static Cipher
initCipherForBlock(Cipher cipher, int block, EncryptionInfo encryptionInfo, SecretKey skey, int encryptMode)

public void
setChunkSize(int
the chunk size, i.e. the block size with the same encryption key
chunkSize
)

Overrides org.apache.poi.poifs.crypt.Decryptor.setChunkSize.

Sets the chunk size of the data stream.

public boolean
Inherited from org.apache.poi.poifs.crypt.Decryptor:
getBlockSizeInBytesgetDataStreamgetEncryptionInfogetGenericPropertiesgetInstancegetIntegrityHmacKeygetIntegrityHmacValuegetKeySizeInBytesgetSecretKeygetVerifiersetEncryptionInfosetIntegrityHmacKeysetIntegrityHmacValuesetSecretKeysetVerifier

Field Detail

chunkSizeback to summary
private int chunkSize
lengthback to summary
private long length

Constructor Detail

XORDecryptorback to summary
protected XORDecryptor()
XORDecryptorback to summary
protected XORDecryptor(XORDecryptor other)

Method Detail

copyback to summary
public XORDecryptor copy()

Implements abstract org.apache.poi.poifs.crypt.Decryptor.copy.

Annotations
@Override
getDataStreamback to summary
public ChunkedCipherInputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException

Implements abstract org.apache.poi.poifs.crypt.Decryptor.getDataStream.

Doc from org.apache.poi.poifs.crypt.Decryptor.getDataStream.

Return a stream with decrypted data.

Use getLength() to get the size of that data that can be safely read from the stream. Just reading to the end of the input stream is not sufficient because there are normally padding bytes that must be discarded

Parameters
dir:DirectoryNode

the node to read from

Returns:ChunkedCipherInputStream

decrypted stream

Annotations
@Override
getDataStreamback to summary
public InputStream getDataStream(InputStream stream, int size, int initialPos) throws IOException, GeneralSecurityException

Overrides org.apache.poi.poifs.crypt.Decryptor.getDataStream.

Doc from org.apache.poi.poifs.crypt.Decryptor.getDataStream.

Wraps a stream for decryption

As we are handling streams and don't know the total length beforehand, it's the callers duty to care for the length of the entries.

Parameters
stream:InputStream

the stream to be wrapped

initialPos:int

initial/current byte position within the stream

Returns:InputStream

decrypted stream

Annotations
@Override
getLengthback to summary
public long getLength()

Implements abstract org.apache.poi.poifs.crypt.Decryptor.getLength.

Doc from org.apache.poi.poifs.crypt.Decryptor.getLength.

Returns the length of the encrypted data that can be safely read with getDataStream(org.apache.poi.poifs.filesystem.DirectoryNode). Just reading to the end of the input stream is not sufficient because there are normally padding bytes that must be discarded

The length variable is initialized in getDataStream(org.apache.poi.poifs.filesystem.DirectoryNode), an attempt to call getLength() prior to getDataStream() will result in IllegalStateException.

Returns:long

length of the encrypted data

Annotations
@Override
initCipherForBlockback to summary
public Cipher initCipherForBlock(Cipher cipher, int block) throws GeneralSecurityException

Overrides org.apache.poi.poifs.crypt.Decryptor.initCipherForBlock.

Doc from org.apache.poi.poifs.crypt.Decryptor.initCipherForBlock.

Initializes a cipher object for a given block index for encryption

Parameters
cipher:Cipher

may be null, otherwise the given instance is reset to the new block index

block:int

the block index, e.g. the persist/slide id (hslf)

Returns:Cipher

a new cipher object, if cipher was null, otherwise the reinitialized cipher

Annotations
@Override
Exceptions
GeneralSecurityException:
if the cipher can't be initialized
initCipherForBlockback to summary
protected static Cipher initCipherForBlock(Cipher cipher, int block, EncryptionInfo encryptionInfo, SecretKey skey, int encryptMode) throws GeneralSecurityException
setChunkSizeback to summary
public void setChunkSize(int chunkSize)

Overrides org.apache.poi.poifs.crypt.Decryptor.setChunkSize.

Doc from org.apache.poi.poifs.crypt.Decryptor.setChunkSize.

Sets the chunk size of the data stream. Needs to be set before the data stream is requested. When not set, the implementation uses method specific default values

Parameters
chunkSize:int

the chunk size, i.e. the block size with the same encryption key

Annotations
@Override
verifyPasswordback to summary
public boolean verifyPassword(String password)

Implements abstract org.apache.poi.poifs.crypt.Decryptor.verifyPassword.

Annotations
@Override
org.apache.poi.poifs.crypt.xor back to summary

private Class XORDecryptor.XORCipherInputStream

extends ChunkedCipherInputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final int
private int
private int

Constructor Summary

AccessConstructor and Description
public
XORCipherInputStream(InputStream stream, int initialPos)

Method Summary

Modifier and TypeMethod and Description
protected Cipher
protected int
invokeCipher(int totalBytes, boolean doFinal)

Overrides org.apache.poi.poifs.crypt.ChunkedCipherInputStream.invokeCipher.

Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses its own implementation

private byte
rotateLeft(byte bits, int shift)

public void
setNextRecordSize(int
the size of the next record
recordSize
)

Overrides org.apache.poi.poifs.crypt.ChunkedCipherInputStream.setNextRecordSize.

Decrypts a xor obfuscated byte array.

Inherited from org.apache.poi.poifs.crypt.ChunkedCipherInputStream:
availablegetChunkgetChunkMaskgetPlaingetPosinitCipherForBlockmarkmarkSupportedreadreadreadPlainresetskip

Field Detail

initialOffsetback to summary
private final int initialOffset
recordEndback to summary
private int recordEnd
recordStartback to summary
private int recordStart

Constructor Detail

XORCipherInputStreamback to summary
public XORCipherInputStream(InputStream stream, int initialPos) throws GeneralSecurityException

Method Detail

initCipherForBlockback to summary
protected Cipher initCipherForBlock(Cipher existing, int block) throws GeneralSecurityException

Implements abstract org.apache.poi.poifs.crypt.ChunkedCipherInputStream.initCipherForBlock.

Annotations
@Override
invokeCipherback to summary
protected int invokeCipher(int totalBytes, boolean doFinal)

Overrides org.apache.poi.poifs.crypt.ChunkedCipherInputStream.invokeCipher.

Doc from org.apache.poi.poifs.crypt.ChunkedCipherInputStream.invokeCipher.

Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses its own implementation

Annotations
@Override
rotateLeftback to summary
private byte rotateLeft(byte bits, int shift)
setNextRecordSizeback to summary
public void setNextRecordSize(int recordSize)

Overrides org.apache.poi.poifs.crypt.ChunkedCipherInputStream.setNextRecordSize.

Decrypts a xor obfuscated byte array. The data is decrypted in-place

Parameters
recordSize:int

Doc from org.apache.poi.poifs.crypt.ChunkedCipherInputStream.setNextRecordSize.

the size of the next record

Annotations
@Override
See Also
2.3.7.3 Binary Document XOR Data Transformation Method 1