Class PGPEncryptedDataList

java.lang.Object
org.bouncycastle.openpgp.PGPEncryptedDataList
All Implemented Interfaces:
Iterable<PGPEncryptedData>, org.bouncycastle.util.Iterable<PGPEncryptedData>

public class PGPEncryptedDataList extends Object implements org.bouncycastle.util.Iterable<PGPEncryptedData>
A holder for a list of PGP encryption method packets and the encrypted data associated with them.

This holder supports reading a sequence of the following encryption methods, followed by an encrypted data packet:

All of the objects returned from this holder share a reference to the same encrypted data input stream, which can only be consumed once.

  • Constructor Details

  • Method Details

    • isIntegrityProtected

      public boolean isIntegrityProtected()
      Checks whether the packet is integrity protected.
      Returns:
      true if there is a modification detection code package associated with this stream
    • get

      public PGPEncryptedData get(int index)
      Gets the encryption method object at the specified index.
      Parameters:
      index - the encryption method to obtain (0 based).
    • getEncryptedData

      public InputStreamPacket getEncryptedData()
    • size

      public int size()
      Gets the number of encryption methods in this list.
    • isEmpty

      public boolean isEmpty()
      Returns true iff there are 0 encryption methods in this list.
    • getEncryptedDataObjects

      public 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.
    • iterator

      public Iterator<PGPEncryptedData> iterator()
      Support method for Iterable where available.
      Specified by:
      iterator in interface Iterable<PGPEncryptedData>
      Specified by:
      iterator in interface org.bouncycastle.util.Iterable<PGPEncryptedData>
    • extractSessionKeyEncryptedData

      public PGPSessionKeyEncryptedData extractSessionKeyEncryptedData()
      Create a decryption method using a PGPSessionKey. This method can be used to decrypt messages which do not contain a SKESK or PKESK packet using a session key.
      Returns:
      session key encrypted data
    • extractSessionKeyEncryptedData

      public PGPSessionKeyEncryptedData extractSessionKeyEncryptedData(boolean passwordDerivedSessionKey)
      Create a decryption method using a 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.

      Parameters:
      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.
      Returns:
      session key encrypted data