<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.1" />

PgpEncryptedDataList

using Org.BouncyCastle.Utilities.Collections; using System; using System.Collections.Generic; using System.IO; namespace Org.BouncyCastle.Bcpg.OpenPgp { public class PgpEncryptedDataList : PgpObject { private readonly List<PgpEncryptedData> m_list = new List<PgpEncryptedData>(); private readonly InputStreamPacket m_data; public PgpEncryptedData this[int index] { get { return m_list[index]; } } public int Count => m_list.Count; public bool IsEmpty => m_list.Count == 0; public PgpEncryptedDataList(BcpgInputStream bcpgInput) { List<Packet> list = new List<Packet>(); while (bcpgInput.NextPacketTag() == PacketTag.PublicKeyEncryptedSession || bcpgInput.NextPacketTag() == PacketTag.SymmetricKeyEncryptedSessionKey) { list.Add(bcpgInput.ReadPacket()); } Packet packet = bcpgInput.ReadPacket(); InputStreamPacket inputStreamPacket = packet as InputStreamPacket; if (inputStreamPacket == null) throw new IOException("unexpected packet in stream: " + packet?.ToString()); m_data = inputStreamPacket; foreach (Packet item in list) { SymmetricKeyEncSessionPacket symmetricKeyEncSessionPacket = item as SymmetricKeyEncSessionPacket; if (symmetricKeyEncSessionPacket != null) m_list.Add(new PgpPbeEncryptedData(symmetricKeyEncSessionPacket, m_data)); else { PublicKeyEncSessionPacket publicKeyEncSessionPacket = item as PublicKeyEncSessionPacket; if (publicKeyEncSessionPacket == null) throw new InvalidOperationException(); m_list.Add(new PgpPublicKeyEncryptedData(publicKeyEncSessionPacket, m_data)); } } } public IEnumerable<PgpEncryptedData> GetEncryptedDataObjects() { return CollectionUtilities.Proxy(m_list); } } }