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

CmsCompressedDataParser

using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Cms; using Org.BouncyCastle.Utilities.IO.Compression; using System.IO; namespace Org.BouncyCastle.Cms { public class CmsCompressedDataParser : CmsContentInfoParser { public CmsCompressedDataParser(byte[] compressedData) : this(new MemoryStream(compressedData, false)) { } public CmsCompressedDataParser(Stream compressedData) : base(compressedData) { } public CmsTypedStream GetContent() { try { ContentInfoParser encapContentInfo = new CompressedDataParser((Asn1SequenceParser)contentInfo.GetContent(16)).GetEncapContentInfo(); return new CmsTypedStream(inStream: ZLib.DecompressInput(((Asn1OctetStringParser)encapContentInfo.GetContent(4)).GetOctetStream(), false), oid: encapContentInfo.ContentType.Id); } catch (IOException innerException) { throw new CmsException("IOException reading compressed content.", innerException); } } } }