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

PasswordRecipientInfo

using Org.BouncyCastle.Asn1.X509; using System; namespace Org.BouncyCastle.Asn1.Cms { public class PasswordRecipientInfo : Asn1Encodable { private readonly DerInteger m_version; private readonly AlgorithmIdentifier m_keyDerivationAlgorithm; private readonly AlgorithmIdentifier m_keyEncryptionAlgorithm; private readonly Asn1OctetString m_encryptedKey; public DerInteger Version => m_version; public AlgorithmIdentifier KeyDerivationAlgorithm => m_keyDerivationAlgorithm; public AlgorithmIdentifier KeyEncryptionAlgorithm => m_keyEncryptionAlgorithm; public Asn1OctetString EncryptedKey => m_encryptedKey; public static PasswordRecipientInfo GetInstance(object obj) { if (obj == null) return null; PasswordRecipientInfo passwordRecipientInfo = obj as PasswordRecipientInfo; if (passwordRecipientInfo != null) return passwordRecipientInfo; return new PasswordRecipientInfo(Asn1Sequence.GetInstance(obj)); } public static PasswordRecipientInfo GetInstance(Asn1TaggedObject obj, bool explicitly) { return new PasswordRecipientInfo(Asn1Sequence.GetInstance(obj, explicitly)); } public static PasswordRecipientInfo GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) { return new PasswordRecipientInfo(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); } public PasswordRecipientInfo(AlgorithmIdentifier keyEncryptionAlgorithm, Asn1OctetString encryptedKey) : this(null, keyEncryptionAlgorithm, encryptedKey) { } public PasswordRecipientInfo(AlgorithmIdentifier keyDerivationAlgorithm, AlgorithmIdentifier keyEncryptionAlgorithm, Asn1OctetString encryptedKey) { m_version = DerInteger.Zero; m_keyDerivationAlgorithm = keyDerivationAlgorithm; if (keyEncryptionAlgorithm == null) throw new ArgumentNullException("keyEncryptionAlgorithm"); m_keyEncryptionAlgorithm = keyEncryptionAlgorithm; if (encryptedKey == null) throw new ArgumentNullException("encryptedKey"); m_encryptedKey = encryptedKey; } [Obsolete("Use 'GetInstance' instead")] public PasswordRecipientInfo(Asn1Sequence seq) { int count = seq.Count; int sequencePosition = 0; if (count < 3 || count > 4) throw new ArgumentException("Bad sequence size: " + count.ToString(), "seq"); m_version = DerInteger.GetInstance(seq[sequencePosition++]); m_keyDerivationAlgorithm = Asn1Utilities.ReadOptionalContextTagged(seq, ref sequencePosition, 0, false, AlgorithmIdentifier.GetTagged); m_keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[sequencePosition++]); m_encryptedKey = Asn1OctetString.GetInstance(seq[sequencePosition++]); } public override Asn1Object ToAsn1Object() { if (m_keyDerivationAlgorithm == null) return new DerSequence(m_version, m_keyEncryptionAlgorithm, m_encryptedKey); return new DerSequence(m_version, new DerTaggedObject(false, 0, m_keyDerivationAlgorithm), m_keyEncryptionAlgorithm, m_encryptedKey); } } }