public class PGPEncryptedDataList extends java.lang.Object implements org.bouncycastle.util.Iterable<PGPEncryptedData>
This holder supports reading a sequence of the following encryption methods, followed by an encrypted data packet:
PacketTags.SYMMETRIC_KEY_ENC_SESSION - produces a PGPPBEEncryptedDataPacketTags.PUBLIC_KEY_ENC_SESSION - produces a PGPPublicKeyEncryptedDataAll of the objects returned from this holder share a reference to the same encrypted data input stream, which can only be consumed once.
| Constructor and Description |
|---|
PGPEncryptedDataList(BCPGInputStream pIn)
Construct an encrypted data packet holder, reading PGP encrypted method packets and an
encrypted data packet from the stream.
|
PGPEncryptedDataList(byte[] encData)
Construct an encrypted data packet holder, reading PGP encrypted method packets and an
encrypted data packet from a stream.
|
PGPEncryptedDataList(java.io.InputStream inStream)
Construct an encrypted data packet holder, reading PGP encrypted method packets and an
encrypted data packet from a stream.
|
| Modifier and Type | Method and Description |
|---|---|
PGPSessionKeyEncryptedData |
extractSessionKeyEncryptedData()
Create a decryption method using a
PGPSessionKey. |
PGPSessionKeyEncryptedData |
extractSessionKeyEncryptedData(boolean passwordDerivedSessionKey)
Create a decryption method using a
PGPSessionKey, stating whether the session key was recovered
from a password. |
PGPEncryptedData |
get(int index)
Gets the encryption method object at the specified index.
|
InputStreamPacket |
getEncryptedData() |
java.util.Iterator<PGPEncryptedData> |
getEncryptedDataObjects()
Returns an iterator over the encryption method objects held in this list, in the order they
appeared in the stream they are read from.
|
boolean |
isEmpty()
Returns
true iff there are 0 encryption methods in this list. |
boolean |
isIntegrityProtected()
Checks whether the packet is integrity protected.
|
java.util.Iterator<PGPEncryptedData> |
iterator()
Support method for Iterable where available.
|
int |
size()
Gets the number of encryption methods in this list.
|
public PGPEncryptedDataList(byte[] encData)
throws java.io.IOException
The first packet in the stream should be one of PacketTags.SYMMETRIC_KEY_ENC_SESSION
or PacketTags.PUBLIC_KEY_ENC_SESSION.
encData - a byte array containing an encrypted stream.java.io.IOException - if an error occurs reading from the PGP input.public PGPEncryptedDataList(java.io.InputStream inStream)
throws java.io.IOException
The first packet in the stream should be one of PacketTags.SYMMETRIC_KEY_ENC_SESSION
or PacketTags.PUBLIC_KEY_ENC_SESSION.
inStream - the input stream being read.java.io.IOException - if an error occurs reading from the PGP input.public PGPEncryptedDataList(BCPGInputStream pIn) throws java.io.IOException
The next packet in the stream should be one of PacketTags.SYMMETRIC_KEY_ENC_SESSION
or PacketTags.PUBLIC_KEY_ENC_SESSION.
pIn - the PGP object stream being read.java.io.IOException - if an error occurs reading from the PGP input.public boolean isIntegrityProtected()
true if there is a modification detection code package associated with
this streampublic PGPEncryptedData get(int index)
index - the encryption method to obtain (0 based).public InputStreamPacket getEncryptedData()
public int size()
public boolean isEmpty()
true iff there are 0 encryption methods in this list.public java.util.Iterator<PGPEncryptedData> getEncryptedDataObjects()
public java.util.Iterator<PGPEncryptedData> iterator()
iterator in interface java.lang.Iterable<PGPEncryptedData>public PGPSessionKeyEncryptedData extractSessionKeyEncryptedData()
PGPSessionKey. This method can be used to decrypt messages which do not
contain a SKESK or PKESK packet using a session key.public PGPSessionKeyEncryptedData extractSessionKeyEncryptedData(boolean passwordDerivedSessionKey)
PGPSessionKey, stating whether the session key was recovered
from a password. This method can be used to decrypt messages which do not contain a SKESK or PKESK packet
using a session key.
A session key recovered from a SKESK packet with the wrong passphrase is a well formed key which simply
decrypts to garbage, and on a SEIPD v1 (or SED) packet the legacy CFB "quick check" on the two repeated
prefix bytes is what detects that - so passing true here makes the wrong passphrase surface as a
PGPDataValidationException from PGPSessionKeyEncryptedData.getDataStream(org.bouncycastle.openpgp.operator.SessionKeyDataDecryptorFactory),
as it does when the same packet is decrypted in one step through PGPPBEEncryptedData, rather than
as a parse failure further down the stream.
It must be passed true only for a session key that was recovered from a password. Reporting the quick
check for a session key that came from a public key operation - one recovered from a PKESK packet, or one
held from an earlier decryption - re-creates the Mister-Zuccherato oracle on the CFB prefix, which is why
extractSessionKeyEncryptedData() never reports it. A SEIPD v2 (AEAD) packet carries no such
check and is unaffected either way.
passwordDerivedSessionKey - true if the session key was recovered from a password (a SKESK packet),
false if it came from a public key operation or from anywhere else.