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

public Class CryptoAPIDecryptor

extends Decryptor
Class Inheritance
Imports
java.io.EOFException, .IOException, .InputStream, java.security.GeneralSecurityException, .MessageDigest, java.util.Arrays, javax.crypto.Cipher, .SecretKey, javax.crypto.spec.SecretKeySpec, org.apache.commons.io.input.BoundedInputStream, org.apache.poi.EncryptedDocumentException, org.apache.poi.poifs.crypt.ChunkedCipherInputStream, .CryptoFunctions, .Decryptor, .EncryptionHeader, .EncryptionInfo, .EncryptionVerifier, .HashAlgorithm, org.apache.poi.poifs.filesystem.DirectoryNode, .DocumentInputStream, .POIFSFileSystem, org.apache.poi.util.BitField, .BitFieldFactory, .IOUtils, .LittleEndian, .LittleEndianInputStream, .StringUtil

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
pack-priv static 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 CryptoAPIDecryptor
protected static SecretKey
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 ChunkedCipherInputStream
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

Returns:

the length of the stream returned by getDataStream(DirectoryNode)
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 POIFSFileSystem
getSummaryEntries(DirectoryNode
root directory node of the OLE file containing the encrypted properties
root
,
String
name of the encrypted stream - "encryption" for HSSF/HWPF, "encryptedStream" (or encryptedSummary?) for HSLF
encryptedStream
)

Decrypt the Document-/SummaryInformation and other optionally streams.

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

CryptoAPIDecryptorback to summary
protected CryptoAPIDecryptor()
CryptoAPIDecryptorback to summary
protected CryptoAPIDecryptor(CryptoAPIDecryptor other)

Method Detail

copyback to summary
public CryptoAPIDecryptor copy()

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

Annotations
@Override
generateSecretKeyback to summary
protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver)
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 ChunkedCipherInputStream 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:ChunkedCipherInputStream

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

the length of the stream returned by getDataStream(DirectoryNode)

Annotations
@Override
getSummaryEntriesback to summary
public POIFSFileSystem getSummaryEntries(DirectoryNode root, String encryptedStream) throws IOException, GeneralSecurityException

Decrypt the Document-/SummaryInformation and other optionally streams. Opposed to other crypto modes, cryptoapi is record based and can't be used to stream-decrypt a whole file.

Summary entries are only encrypted within cryptoapi encrypted files. Binary RC4 encrypted files use non-encrypted/default property sets

Parameters
root:DirectoryNode

root directory node of the OLE file containing the encrypted properties

encryptedStream:String

name of the encrypted stream - "encryption" for HSSF/HWPF, "encryptedStream" (or encryptedSummary?) for HSLF

See Also
2.3.5.4 RC4 CryptoAPI Encrypted Summary Stream
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.cryptoapi back to summary

private Class CryptoAPIDecryptor.CryptoAPICipherInputStream

extends ChunkedCipherInputStream
Class Inheritance

Constructor Summary

AccessConstructor and Description
public
CryptoAPICipherInputStream(InputStream stream, long size, int initialPos)

Method Summary

Modifier and TypeMethod and Description
protected Cipher
Inherited from org.apache.poi.poifs.crypt.ChunkedCipherInputStream:
availablegetChunkgetChunkMaskgetPlaingetPosinitCipherForBlockinvokeCiphermarkmarkSupportedreadreadreadPlainresetsetNextRecordSizeskip

Constructor Detail

CryptoAPICipherInputStreamback to summary
public CryptoAPICipherInputStream(InputStream stream, long size, 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
org.apache.poi.poifs.crypt.cryptoapi back to summary

pack-priv Class CryptoAPIDecryptor.StreamDescriptorEntry

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIDecryptor.StreamDescriptorEntry

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int
pack-priv static final BitField
pack-priv int
pack-priv String
pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockback to summary
pack-priv int block
flagsback to summary
pack-priv int flags
flagStreamback to summary
pack-priv static final BitField flagStream
reserved2back to summary
pack-priv int reserved2
streamNameback to summary
pack-priv String streamName
streamOffsetback to summary
pack-priv int streamOffset
streamSizeback to summary
pack-priv int streamSize

Constructor Detail

StreamDescriptorEntryback to summary
pack-priv StreamDescriptorEntry()