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

public abstract Class Decryptor

extends Object
implements GenericRecord
Class Inheritance
All Implemented Interfaces
org.apache.poi.common.usermodel.GenericRecord
Known Direct Subclasses
org.apache.poi.poifs.crypt.agile.AgileDecryptor, org.apache.poi.poifs.crypt.binaryrc4.BinaryRC4Decryptor, org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIDecryptor, org.apache.poi.poifs.crypt.standard.StandardDecryptor, org.apache.poi.poifs.crypt.xor.XORDecryptor
Imports
java.io.IOException, .InputStream, java.security.GeneralSecurityException, java.util.Map, java.util.function.Supplier, javax.crypto.Cipher, .SecretKey, org.apache.poi.EncryptedDocumentException, org.apache.poi.common.usermodel.GenericRecord, org.apache.poi.poifs.filesystem.DirectoryNode, .POIFSFileSystem, org.apache.poi.util.GenericRecordUtil

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
protected EncryptionInfo
private byte[]
private byte[]
private SecretKey
private byte[]

Constructor Summary

AccessConstructor and Description
protected
protected

Method Summary

Modifier and TypeMethod and Description
public abstract Decryptor
copy()

protected int
public abstract InputStream

Returns:

decrypted stream
getDataStream
(DirectoryNode
the node to read from
dir
)

Return a stream with decrypted data.

public InputStream

Returns:

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

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 InputStream
public EncryptionInfo
public Map<String, Supplier<?>>
public static Decryptor
public byte[]
public byte[]
protected int
public abstract long

Returns:

length of the encrypted data
getLength
()

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

public SecretKey
public byte[]
public Cipher

Returns:

a new cipher object, if cipher was null, otherwise the reinitialized 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
)

Initializes a cipher object for a given block index for encryption

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

Sets the chunk size of the data stream.

public void
protected void
setIntegrityHmacKey(byte[] integrityHmacKey)

protected void
setIntegrityHmacValue(byte[] integrityHmacValue)

protected void
protected void
setVerifier(byte[] verifier)

public abstract boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_PASSWORDback to summary
public static final String DEFAULT_PASSWORD
Annotations
@SuppressWarnings:squid:S2068
DEFAULT_POIFS_ENTRYback to summary
public static final String DEFAULT_POIFS_ENTRY
encryptionInfoback to summary
protected EncryptionInfo encryptionInfo
integrityHmacKeyback to summary
private byte[] integrityHmacKey
integrityHmacValueback to summary
private byte[] integrityHmacValue
secretKeyback to summary
private SecretKey secretKey
verifierback to summary
private byte[] verifier

Constructor Detail

Decryptorback to summary
protected Decryptor()
Decryptorback to summary
protected Decryptor(Decryptor other)

Method Detail

copyback to summary
public abstract Decryptor copy()
getBlockSizeInBytesback to summary
protected int getBlockSizeInBytes()
Annotations
@SuppressWarnings:unused
getDataStreamback to summary
public abstract InputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException

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:InputStream

decrypted stream

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

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

getDataStreamback to summary
public InputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException
getEncryptionInfoback to summary
public EncryptionInfo getEncryptionInfo()
getGenericPropertiesback to summary
public Map<String, Supplier<?>> getGenericProperties()

Implements org.apache.poi.common.usermodel.GenericRecord.getGenericProperties.

Annotations
@Override
getInstanceback to summary
public static Decryptor getInstance(EncryptionInfo info)
getIntegrityHmacKeyback to summary
public byte[] getIntegrityHmacKey()
getIntegrityHmacValueback to summary
public byte[] getIntegrityHmacValue()
Annotations
@SuppressWarnings:unused
getKeySizeInBytesback to summary
protected int getKeySizeInBytes()
getLengthback to summary
public abstract long 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

Exceptions
IllegalStateException:
if getDataStream(org.apache.poi.poifs.filesystem.DirectoryNode) was not called
getSecretKeyback to summary
public SecretKey getSecretKey()
getVerifierback to summary
public byte[] getVerifier()
initCipherForBlockback to summary
public Cipher initCipherForBlock(Cipher cipher, int block) throws GeneralSecurityException

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

Exceptions
GeneralSecurityException:
if the cipher can't be initialized
setChunkSizeback to summary
public void setChunkSize(int chunkSize)

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

setEncryptionInfoback to summary
public void setEncryptionInfo(EncryptionInfo encryptionInfo)
setIntegrityHmacKeyback to summary
protected void setIntegrityHmacKey(byte[] integrityHmacKey)
setIntegrityHmacValueback to summary
protected void setIntegrityHmacValue(byte[] integrityHmacValue)
setSecretKeyback to summary
protected void setSecretKey(SecretKey secretKey)
setVerifierback to summary
protected void setVerifier(byte[] verifier)
verifyPasswordback to summary
public abstract boolean verifyPassword(String password) throws GeneralSecurityException