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

Org.BouncyCastle.Cms.CmsAuthenticatedDataStreamGenerator

Streaming generator for CMS AuthenticatedData (MAC-protected) messages. Add recipients via the base CmsAuthenticatedGenerator methods, then call Open to obtain a Stream to which the content to be authenticated is written; closing that stream finalizes the CMS structure and emits the MAC.
namespace Org.BouncyCastle.Cms { public class CmsAuthenticatedDataStreamGenerator : CmsAuthenticatedGenerator { public CmsAuthenticatedDataStreamGenerator(); public CmsAuthenticatedDataStreamGenerator(SecureRandom random); public void SetBufferSize(int bufferSize); public void SetBerEncodeRecipients(bool berEncodeRecipientSet); protected Stream Open(Stream outStr, AlgorithmIdentifier macAlgId, ICipherParameters cipherParameters, Asn1EncodableVector recipientInfos); public Stream Open(Stream outStr, string encryptionOid); public Stream Open(Stream outStr, string encryptionOid, int keySize); } }