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

SubjectPublicKeyInfo

using System; namespace Org.BouncyCastle.Asn1.X509 { public class SubjectPublicKeyInfo : Asn1Encodable { private readonly AlgorithmIdentifier m_algorithm; private readonly DerBitString m_publicKey; public AlgorithmIdentifier Algorithm => m_algorithm; [Obsolete("Use 'Algorithm' instead")] public AlgorithmIdentifier AlgorithmID { get { return m_algorithm; } } public DerBitString PublicKey => m_publicKey; [Obsolete("Use 'PublicKey' instead")] public DerBitString PublicKeyData { get { return m_publicKey; } } public static SubjectPublicKeyInfo GetInstance(object obj) { if (obj == null) return null; SubjectPublicKeyInfo subjectPublicKeyInfo = obj as SubjectPublicKeyInfo; if (subjectPublicKeyInfo != null) return subjectPublicKeyInfo; return new SubjectPublicKeyInfo(Asn1Sequence.GetInstance(obj)); } public static SubjectPublicKeyInfo GetInstance(Asn1TaggedObject obj, bool explicitly) { return new SubjectPublicKeyInfo(Asn1Sequence.GetInstance(obj, explicitly)); } public static SubjectPublicKeyInfo GetOptional(Asn1Encodable element) { if (element == null) throw new ArgumentNullException("element"); SubjectPublicKeyInfo subjectPublicKeyInfo = element as SubjectPublicKeyInfo; if (subjectPublicKeyInfo != null) return subjectPublicKeyInfo; Asn1Sequence optional = Asn1Sequence.GetOptional(element); if (optional != null) return new SubjectPublicKeyInfo(optional); return null; } public static SubjectPublicKeyInfo GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) { return new SubjectPublicKeyInfo(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); } public SubjectPublicKeyInfo(AlgorithmIdentifier algID, DerBitString publicKey) { m_algorithm = algID; m_publicKey = publicKey; } public SubjectPublicKeyInfo(AlgorithmIdentifier algID, Asn1Encodable publicKey) { m_algorithm = algID; m_publicKey = new DerBitString(publicKey); } public SubjectPublicKeyInfo(AlgorithmIdentifier algID, byte[] publicKey) { m_algorithm = algID; m_publicKey = new DerBitString(publicKey); } private SubjectPublicKeyInfo(Asn1Sequence seq) { int count = seq.Count; if (count != 2) throw new ArgumentException("Bad sequence size: " + count.ToString(), "seq"); m_algorithm = AlgorithmIdentifier.GetInstance(seq[0]); m_publicKey = DerBitString.GetInstance(seq[1]); } public Asn1Object ParsePublicKey() { return Asn1Object.FromMemoryStream(m_publicKey.GetOctetMemoryStream()); } public override Asn1Object ToAsn1Object() { return new DerSequence(m_algorithm, m_publicKey); } } }