EncryptedContentInfo
using Org.BouncyCastle.Asn1.X509;
using System;
namespace Org.BouncyCastle.Asn1.Cms
{
public class EncryptedContentInfo : Asn1Encodable
{
private DerObjectIdentifier m_contentType;
private AlgorithmIdentifier m_contentEncryptionAlgorithm;
private Asn1OctetString m_encryptedContent;
public DerObjectIdentifier ContentType => m_contentType;
public AlgorithmIdentifier ContentEncryptionAlgorithm => m_contentEncryptionAlgorithm;
public Asn1OctetString EncryptedContent => m_encryptedContent;
public static EncryptedContentInfo GetInstance(object obj)
{
if (obj == null)
return null;
EncryptedContentInfo encryptedContentInfo = obj as EncryptedContentInfo;
if (encryptedContentInfo != null)
return encryptedContentInfo;
return new EncryptedContentInfo(Asn1Sequence.GetInstance(obj));
}
public static EncryptedContentInfo GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new EncryptedContentInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
}
public static EncryptedContentInfo GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new EncryptedContentInfo(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
}
public EncryptedContentInfo(DerObjectIdentifier contentType, AlgorithmIdentifier contentEncryptionAlgorithm, Asn1OctetString encryptedContent)
{
if (contentType == null)
throw new ArgumentNullException("contentType");
m_contentType = contentType;
if (contentEncryptionAlgorithm == null)
throw new ArgumentNullException("contentEncryptionAlgorithm");
m_contentEncryptionAlgorithm = contentEncryptionAlgorithm;
m_encryptedContent = encryptedContent;
}
[Obsolete("Use 'GetInstance' instead")]
public EncryptedContentInfo(Asn1Sequence seq)
{
int count = seq.Count;
int sequencePosition = 0;
if (count < 2 || count > 3)
throw new ArgumentException("Bad sequence size: " + count.ToString(), "seq");
m_contentType = DerObjectIdentifier.GetInstance(seq[sequencePosition++]);
m_contentEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[sequencePosition++]);
m_encryptedContent = Asn1Utilities.ReadOptionalContextTagged(seq, ref sequencePosition, 0, false, Asn1OctetString.GetTagged);
if (sequencePosition != count)
throw new ArgumentException("Unexpected elements in sequence", "seq");
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(3);
asn1EncodableVector.Add(m_contentType, m_contentEncryptionAlgorithm);
if (m_encryptedContent != null)
asn1EncodableVector.Add(new BerTaggedObject(false, 0, m_encryptedContent));
return new BerSequence(asn1EncodableVector);
}
}
}