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

CmsAuthenticatedData

public class CmsAuthenticatedData
using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Cms; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Utilities; using System; using System.IO; namespace Org.BouncyCastle.Cms { public class CmsAuthenticatedData { private readonly ContentInfo m_contentInfo; private readonly AuthenticatedData m_authenticatedData; private readonly RecipientInformationStore m_recipientInfoStore; public AuthenticatedData AuthenticatedData => m_authenticatedData; public AlgorithmIdentifier MacAlgorithmID => m_authenticatedData.MacAlgorithm; public string MacAlgOid => MacAlgorithmID.Algorithm.GetID(); public ContentInfo ContentInfo => m_contentInfo; public CmsAuthenticatedData(byte[] authData) : this(CmsUtilities.ReadContentInfo(authData)) { } public CmsAuthenticatedData(Stream authData) : this(CmsUtilities.ReadContentInfo(authData)) { } public CmsAuthenticatedData(ContentInfo contentInfo) { if (contentInfo == null) throw new ArgumentNullException("contentInfo"); m_contentInfo = contentInfo; m_authenticatedData = AuthenticatedData.GetInstance(contentInfo.Content); Asn1Set recipientInfos = m_authenticatedData.RecipientInfos; CmsReadable readable = new CmsProcessableByteArray(Asn1OctetString.GetInstance(m_authenticatedData.EncapsulatedContentInfo.Content).GetOctets()); CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable(m_authenticatedData.MacAlgorithm, readable); m_recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(recipientInfos, secureReadable); } public byte[] GetMac() { return Arrays.Clone(m_authenticatedData.Mac.GetOctets()); } public RecipientInformationStore GetRecipientInfos() { return m_recipientInfoStore; } public Org.BouncyCastle.Asn1.Cms.AttributeTable GetAuthAttrs() { Asn1Set authAttrs = m_authenticatedData.AuthAttrs; if (authAttrs == null) return null; return authAttrs.ToAttributeTable(); } public Org.BouncyCastle.Asn1.Cms.AttributeTable GetUnauthAttrs() { Asn1Set unauthAttrs = m_authenticatedData.UnauthAttrs; if (unauthAttrs == null) return null; return unauthAttrs.ToAttributeTable(); } public byte[] GetEncoded() { return m_contentInfo.GetEncoded(); } } }