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

SignerInfo

public class SignerInfo : Asn1Encodable
Represents per-signer information within a SignedData
using Org.BouncyCastle.Asn1.X509; using System; namespace Org.BouncyCastle.Asn1.Cms { public class SignerInfo : Asn1Encodable { private readonly DerInteger m_version; private readonly SignerIdentifier m_sid; private readonly AlgorithmIdentifier m_digestAlgorithm; private readonly Asn1Set m_signedAttrs; private readonly AlgorithmIdentifier m_signatureAlgorithm; private readonly Asn1OctetString m_signature; private readonly Asn1Set m_unsignedAttrs; [Obsolete("Use 'SignedAttrs' instead")] public Asn1Set AuthenticatedAttributes { get { return m_signedAttrs; } } public AlgorithmIdentifier DigestAlgorithm => m_digestAlgorithm; [Obsolete("Use 'SignatureAlgorithm' instead")] public AlgorithmIdentifier DigestEncryptionAlgorithm { get { return m_signatureAlgorithm; } } [Obsolete("Use 'Signature' instead")] public Asn1OctetString EncryptedDigest { get { return m_signature; } } public Asn1OctetString Signature => m_signature; public AlgorithmIdentifier SignatureAlgorithm => m_signatureAlgorithm; public Asn1Set SignedAttrs => m_signedAttrs; public SignerIdentifier SignerID => m_sid; [Obsolete("Use 'UnsignedAttrs' instead")] public Asn1Set UnauthenticatedAttributes { get { return m_unsignedAttrs; } } public Asn1Set UnsignedAttrs => m_unsignedAttrs; public DerInteger Version => m_version; public static SignerInfo GetInstance(object obj) { if (obj == null) return null; SignerInfo signerInfo = obj as SignerInfo; if (signerInfo != null) return signerInfo; return new SignerInfo(Asn1Sequence.GetInstance(obj)); } public static SignerInfo GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { return new SignerInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); } public static SignerInfo GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) { return new SignerInfo(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); } private SignerInfo(Asn1Sequence seq) { int count = seq.Count; int sequencePosition = 0; if (count < 5 || count > 7) throw new ArgumentException("Bad sequence size: " + count.ToString(), "seq"); m_version = DerInteger.GetInstance(seq[sequencePosition++]); m_sid = SignerIdentifier.GetInstance(seq[sequencePosition++]); m_digestAlgorithm = AlgorithmIdentifier.GetInstance(seq[sequencePosition++]); m_signedAttrs = Asn1Utilities.ReadOptionalContextTagged(seq, ref sequencePosition, 0, false, Asn1Set.GetTagged); m_signatureAlgorithm = AlgorithmIdentifier.GetInstance(seq[sequencePosition++]); m_signature = Asn1OctetString.GetInstance(seq[sequencePosition++]); m_unsignedAttrs = Asn1Utilities.ReadOptionalContextTagged(seq, ref sequencePosition, 1, false, Asn1Set.GetTagged); if (sequencePosition != count) throw new ArgumentException("Unexpected elements in sequence", "seq"); } public SignerInfo(SignerIdentifier sid, AlgorithmIdentifier digAlgorithm, Attributes authenticatedAttributes, AlgorithmIdentifier digEncryptionAlgorithm, Asn1OctetString encryptedDigest, Attributes unauthenticatedAttributes) : this(sid, digAlgorithm, authenticatedAttributes?.AttributeSet, digEncryptionAlgorithm, encryptedDigest, unauthenticatedAttributes?.AttributeSet) { } public SignerInfo(SignerIdentifier sid, AlgorithmIdentifier digAlgorithm, Asn1Set authenticatedAttributes, AlgorithmIdentifier digEncryptionAlgorithm, Asn1OctetString encryptedDigest, Asn1Set unauthenticatedAttributes) { if (sid == null) throw new ArgumentNullException("sid"); m_sid = sid; if (digAlgorithm == null) throw new ArgumentNullException("digAlgorithm"); m_digestAlgorithm = digAlgorithm; m_signedAttrs = authenticatedAttributes; if (digEncryptionAlgorithm == null) throw new ArgumentNullException("digEncryptionAlgorithm"); m_signatureAlgorithm = digEncryptionAlgorithm; if (encryptedDigest == null) throw new ArgumentNullException("encryptedDigest"); m_signature = encryptedDigest; m_unsignedAttrs = unauthenticatedAttributes; m_version = (sid.IsTagged ? DerInteger.Three : DerInteger.One); } public override Asn1Object ToAsn1Object() { Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(7); asn1EncodableVector.Add(m_version); asn1EncodableVector.Add(m_sid); asn1EncodableVector.Add(m_digestAlgorithm); asn1EncodableVector.AddOptionalTagged(false, 0, m_signedAttrs); asn1EncodableVector.Add(m_signatureAlgorithm); asn1EncodableVector.Add(m_signature); asn1EncodableVector.AddOptionalTagged(false, 1, m_unsignedAttrs); return new DerSequence(asn1EncodableVector); } } }