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

KeyTransRecipientInfo

using Org.BouncyCastle.Asn1.X509; using System; namespace Org.BouncyCastle.Asn1.Cms { public class KeyTransRecipientInfo : Asn1Encodable { private readonly DerInteger m_version; private readonly RecipientIdentifier m_rid; private readonly AlgorithmIdentifier m_keyEncryptionAlgorithm; private readonly Asn1OctetString m_encryptedKey; public DerInteger Version => m_version; public RecipientIdentifier RecipientIdentifier => m_rid; public AlgorithmIdentifier KeyEncryptionAlgorithm => m_keyEncryptionAlgorithm; public Asn1OctetString EncryptedKey => m_encryptedKey; public static KeyTransRecipientInfo GetInstance(object obj) { if (obj == null) return null; KeyTransRecipientInfo keyTransRecipientInfo = obj as KeyTransRecipientInfo; if (keyTransRecipientInfo != null) return keyTransRecipientInfo; return new KeyTransRecipientInfo(Asn1Sequence.GetInstance(obj)); } public static KeyTransRecipientInfo GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { return new KeyTransRecipientInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); } public static KeyTransRecipientInfo GetOptional(Asn1Encodable element) { if (element == null) throw new ArgumentNullException("element"); KeyTransRecipientInfo keyTransRecipientInfo = element as KeyTransRecipientInfo; if (keyTransRecipientInfo != null) return keyTransRecipientInfo; Asn1Sequence optional = Asn1Sequence.GetOptional(element); if (optional != null) return new KeyTransRecipientInfo(optional); return null; } public static KeyTransRecipientInfo GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) { return new KeyTransRecipientInfo(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); } public KeyTransRecipientInfo(RecipientIdentifier rid, AlgorithmIdentifier keyEncryptionAlgorithm, Asn1OctetString encryptedKey) { if (rid == null) throw new ArgumentNullException("rid"); m_rid = rid; if (keyEncryptionAlgorithm == null) throw new ArgumentNullException("keyEncryptionAlgorithm"); m_keyEncryptionAlgorithm = keyEncryptionAlgorithm; if (encryptedKey == null) throw new ArgumentNullException("encryptedKey"); m_encryptedKey = encryptedKey; m_version = (rid.IsTagged ? DerInteger.Two : DerInteger.Zero); } [Obsolete("Use 'GetInstance' instead")] public KeyTransRecipientInfo(Asn1Sequence seq) { int count = seq.Count; if (count != 4) throw new ArgumentException("Bad sequence size: " + count.ToString(), "seq"); m_version = DerInteger.GetInstance(seq[0]); m_rid = RecipientIdentifier.GetInstance(seq[1]); m_keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[2]); m_encryptedKey = Asn1OctetString.GetInstance(seq[3]); } public override Asn1Object ToAsn1Object() { return new DerSequence(m_version, m_rid, m_keyEncryptionAlgorithm, m_encryptedKey); } } }