CreateBerSetFromList() public static method

public static CreateBerSetFromList ( IList berObjects ) : Asn1Set
berObjects IList
return Org.BouncyCastle.Asn1.Asn1Set
            public override void Close()
            {
                this._out.Close();
                this._eiGen.Close();
                this.outer._digests.Clear();
                if (this.outer._certs.Count > 0)
                {
                    Asn1Set obj = CmsUtilities.CreateBerSetFromList(this.outer._certs);
                    CmsSignedDataStreamGenerator.CmsSignedDataOutputStream.WriteToGenerator(this._sigGen, new BerTaggedObject(false, 0, obj));
                }
                if (this.outer._crls.Count > 0)
                {
                    Asn1Set obj2 = CmsUtilities.CreateBerSetFromList(this.outer._crls);
                    CmsSignedDataStreamGenerator.CmsSignedDataOutputStream.WriteToGenerator(this._sigGen, new BerTaggedObject(false, 1, obj2));
                }
                foreach (DictionaryEntry dictionaryEntry in this.outer._messageDigests)
                {
                    this.outer._messageHashes.Add(dictionaryEntry.Key, DigestUtilities.DoFinal((IDigest)dictionaryEntry.Value));
                }
                Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(new Asn1Encodable[0]);

                foreach (CmsSignedDataStreamGenerator.DigestAndSignerInfoGeneratorHolder digestAndSignerInfoGeneratorHolder in this.outer._signerInfs)
                {
                    AlgorithmIdentifier digestAlgorithm = digestAndSignerInfoGeneratorHolder.DigestAlgorithm;
                    byte[] array = (byte[])this.outer._messageHashes[CmsSignedDataStreamGenerator.Helper.GetDigestAlgName(digestAndSignerInfoGeneratorHolder.digestOID)];
                    this.outer._digests[digestAndSignerInfoGeneratorHolder.digestOID] = array.Clone();
                    asn1EncodableVector.Add(new Asn1Encodable[]
                    {
                        digestAndSignerInfoGeneratorHolder.signerInf.Generate(this._contentOID, digestAlgorithm, array)
                    });
                }
                foreach (SignerInformation signerInformation in this.outer._signers)
                {
                    asn1EncodableVector.Add(new Asn1Encodable[]
                    {
                        signerInformation.ToSignerInfo()
                    });
                }
                CmsSignedDataStreamGenerator.CmsSignedDataOutputStream.WriteToGenerator(this._sigGen, new DerSet(asn1EncodableVector));
                this._sigGen.Close();
                this._sGen.Close();
                base.Close();
            }
Exemplo n.º 2
0
        public static CmsSignedData ReplaceCertificatesAndCrls(CmsSignedData signedData, IX509Store x509Certs, IX509Store x509Crls, IX509Store x509AttrCerts)
        {
            if (x509AttrCerts != null)
            {
                throw Platform.CreateNotImplementedException("Currently can't replace attribute certificates");
            }
            CmsSignedData cmsSignedData = new CmsSignedData(signedData);
            Asn1Set       certificates  = null;

            try
            {
                Asn1Set asn1Set = CmsUtilities.CreateBerSetFromList(CmsUtilities.GetCertificatesFromStore(x509Certs));
                if (asn1Set.Count != 0)
                {
                    certificates = asn1Set;
                }
            }
            catch (X509StoreException e)
            {
                throw new CmsException("error getting certificates from store", e);
            }
            Asn1Set crls = null;

            try
            {
                Asn1Set asn1Set2 = CmsUtilities.CreateBerSetFromList(CmsUtilities.GetCrlsFromStore(x509Crls));
                if (asn1Set2.Count != 0)
                {
                    crls = asn1Set2;
                }
            }
            catch (X509StoreException e2)
            {
                throw new CmsException("error getting CRLs from store", e2);
            }
            SignedData signedData2 = signedData.signedData;

            cmsSignedData.signedData  = new SignedData(signedData2.DigestAlgorithms, signedData2.EncapContentInfo, certificates, crls, signedData2.SignerInfos);
            cmsSignedData.contentInfo = new ContentInfo(cmsSignedData.contentInfo.ContentType, cmsSignedData.signedData);
            return(cmsSignedData);
        }
            private void DoClose()
            {
                Platform.Dispose(_out);

                // TODO Parent context(s) should really be be closed explicitly

                _eiGen.Close();

                outer._digests.Clear();                    // clear the current preserved digest state

                if (outer._certs.Count > 0)
                {
                    Asn1Set certs = CmsUtilities.CreateBerSetFromList(outer._certs);

                    WriteToGenerator(_sigGen, new BerTaggedObject(false, 0, certs));
                }

                if (outer._crls.Count > 0)
                {
                    Asn1Set crls = CmsUtilities.CreateBerSetFromList(outer._crls);

                    WriteToGenerator(_sigGen, new BerTaggedObject(false, 1, crls));
                }

                //
                // Calculate the digest hashes
                //
                foreach (DictionaryEntry de in outer._messageDigests)
                {
                    outer._messageHashes.Add(de.Key, DigestUtilities.DoFinal((IDigest)de.Value));
                }

                // TODO If the digest OIDs for precalculated signers weren't mixed in with
                // the others, we could fill in outer._digests here, instead of SignerInfoGenerator.Generate

                //
                // collect all the SignerInfo objects
                //
                Asn1EncodableVector signerInfos = new Asn1EncodableVector();

                //
                // add the generated SignerInfo objects
                //
                {
                    foreach (DigestAndSignerInfoGeneratorHolder holder in outer._signerInfs)
                    {
                        AlgorithmIdentifier digestAlgorithm = holder.DigestAlgorithm;

                        byte[] calculatedDigest = (byte[])outer._messageHashes[
                            Helper.GetDigestAlgName(holder.digestOID)];
                        outer._digests[holder.digestOID] = calculatedDigest.Clone();

                        signerInfos.Add(holder.signerInf.Generate(_contentOID, digestAlgorithm, calculatedDigest));
                    }
                }

                //
                // add the precalculated SignerInfo objects.
                //
                {
                    foreach (SignerInformation signer in outer._signers)
                    {
                        // TODO Verify the content type and calculated digest match the precalculated SignerInfo
//						if (!signer.ContentType.Equals(_contentOID))
//						{
//							// TODO The precalculated content type did not match - error?
//						}
//
//						byte[] calculatedDigest = (byte[])outer._digests[signer.DigestAlgOid];
//						if (calculatedDigest == null)
//						{
//							// TODO We can't confirm this digest because we didn't calculate it - error?
//						}
//						else
//						{
//							if (!Arrays.AreEqual(signer.GetContentDigest(), calculatedDigest))
//							{
//								// TODO The precalculated digest did not match - error?
//							}
//						}

                        signerInfos.Add(signer.ToSignerInfo());
                    }
                }

                WriteToGenerator(_sigGen, new DerSet(signerInfos));

                _sigGen.Close();
                _sGen.Close();
            }
        /**
         * generate a signed object that for a CMS Signed Data
         * object  - if encapsulate is true a copy
         * of the message will be included in the signature. The content type
         * is set according to the OID represented by the string signedContentType.
         */
        public CmsSignedData Generate(
            string signedContentType,
            CmsProcessable content,
            bool encapsulate)
        {
            Asn1EncodableVector digestAlgs  = new Asn1EncodableVector();
            Asn1EncodableVector signerInfos = new Asn1EncodableVector();

            _digests.Clear();             // clear the current preserved digest state

            //
            // add the precalculated SignerInfo objects.
            //
            foreach (SignerInformation signer in _signers)
            {
                digestAlgs.Add(Helper.FixAlgID(signer.DigestAlgorithmID));
                signerInfos.Add(signer.ToSignerInfo());
            }

            //
            // add the SignerInfo objects
            //
            DerObjectIdentifier contentTypeOID;
            bool isCounterSignature;

            if (signedContentType != null)
            {
                contentTypeOID     = new DerObjectIdentifier(signedContentType);
                isCounterSignature = false;
            }
            else
            {
                contentTypeOID     = CmsObjectIdentifiers.Data;
                isCounterSignature = true;
            }

            foreach (SignerInf signer in signerInfs)
            {
                try
                {
                    digestAlgs.Add(Helper.FixAlgID(signer.DigestAlgorithmID));
                    signerInfos.Add(signer.ToSignerInfo(contentTypeOID, content, rand, isCounterSignature));
                }
                catch (IOException e)
                {
                    throw new CmsException("encoding error.", e);
                }
                catch (InvalidKeyException e)
                {
                    throw new CmsException("key inappropriate for signature.", e);
                }
                catch (SignatureException e)
                {
                    throw new CmsException("error creating signature.", e);
                }
                catch (CertificateEncodingException e)
                {
                    throw new CmsException("error creating sid.", e);
                }
            }

            Asn1Set certificates = null;

            if (_certs.Count != 0)
            {
                certificates = CmsUtilities.CreateBerSetFromList(_certs);
            }

            Asn1Set certrevlist = null;

            if (_crls.Count != 0)
            {
                certrevlist = CmsUtilities.CreateBerSetFromList(_crls);
            }

            Asn1OctetString octs = null;

            if (encapsulate)
            {
                MemoryStream bOut = new MemoryStream();
                try
                {
                    content.Write(bOut);
                }
                catch (IOException e)
                {
                    throw new CmsException("encapsulation error.", e);
                }

                octs = new BerOctetString(bOut.ToArray());
            }

            Asn1.Cms.ContentInfo encInfo = new Asn1.Cms.ContentInfo(contentTypeOID, octs);

            Asn1.Cms.SignedData sd = new Asn1.Cms.SignedData(
                new DerSet(digestAlgs),
                encInfo,
                certificates,
                certrevlist,
                new DerSet(signerInfos));

            Asn1.Cms.ContentInfo contentInfo = new Asn1.Cms.ContentInfo(
                PkcsObjectIdentifiers.SignedData, sd);

            return(new CmsSignedData(content, contentInfo));
        }
Exemplo n.º 5
0
        /**
         * generate a signed object that for a CMS Signed Data
         * object  - if encapsulate is true a copy
         * of the message will be included in the signature. The content type
         * is set according to the OID represented by the string signedContentType.
         */
        public CmsSignedData Generate(
            string signedContentType,
            // FIXME Avoid accessing more than once to support CmsProcessableInputStream
            CmsProcessable content,
            bool encapsulate)
        {
            Asn1EncodableVector digestAlgs  = new Asn1EncodableVector();
            Asn1EncodableVector signerInfos = new Asn1EncodableVector();

            _digests.Clear();             // clear the current preserved digest state

            //
            // add the precalculated SignerInfo objects.
            //
            foreach (SignerInformation signer in _signers)
            {
                digestAlgs.Add(Helper.FixAlgID(signer.DigestAlgorithmID));

                // TODO Verify the content type and calculated digest match the precalculated SignerInfo
                signerInfos.Add(signer.ToSignerInfo());
            }

            //
            // add the SignerInfo objects
            //
            bool isCounterSignature = (signedContentType == null);

            DerObjectIdentifier contentTypeOid = isCounterSignature
                ?   null
                                :       new DerObjectIdentifier(signedContentType);

            foreach (SignerInf signer in signerInfs)
            {
                try
                {
                    digestAlgs.Add(signer.DigestAlgorithmID);
                    signerInfos.Add(signer.ToSignerInfo(contentTypeOid, content, rand));
                }
                catch (IOException e)
                {
                    throw new CmsException("encoding error.", e);
                }
                catch (InvalidKeyException e)
                {
                    throw new CmsException("key inappropriate for signature.", e);
                }
                catch (SignatureException e)
                {
                    throw new CmsException("error creating signature.", e);
                }
                catch (CertificateEncodingException e)
                {
                    throw new CmsException("error creating sid.", e);
                }
            }

            Asn1Set certificates = null;

            if (_certs.Count != 0)
            {
                certificates = CmsUtilities.CreateBerSetFromList(_certs);
            }

            Asn1Set certrevlist = null;

            if (_crls.Count != 0)
            {
                certrevlist = CmsUtilities.CreateBerSetFromList(_crls);
            }

            Asn1OctetString octs = null;

            if (encapsulate)
            {
                using (MemoryStream bOut = new MemoryStream())
                {
                    if (content != null)
                    {
                        try
                        {
                            content.Write(bOut);
                        }
                        catch (IOException e)
                        {
                            throw new CmsException("encapsulation error.", e);
                        }
                    }
                    octs = new DerOctetString(bOut.ToArray());
                }
            }

            ContentInfo encInfo = new ContentInfo(contentTypeOid, octs);

            SignedData sd = new SignedData(
                new DerSet(digestAlgs),
                encInfo,
                certificates,
                certrevlist,
                new DerSet(signerInfos));

            ContentInfo contentInfo = new ContentInfo(CmsObjectIdentifiers.SignedData, sd);

            return(new CmsSignedData(content, contentInfo));
        }
Exemplo n.º 6
0
        /**
         * Replace the certificate and CRL information associated with this
         * CmsSignedData object with the new one passed in.
         *
         * @param signedData the signed data object to be used as a base.
         * @param x509Certs the new certificates to be used.
         * @param x509Crls the new CRLs to be used.
         * @return a new signed data object.
         * @exception CmsException if there is an error processing the stores
         */
        public static CmsSignedData ReplaceCertificatesAndCrls(
            CmsSignedData signedData,
            IX509Store x509Certs,
            IX509Store x509Crls,
            IX509Store x509AttrCerts)
        {
            if (x509AttrCerts != null)
            {
                throw Platform.CreateNotImplementedException("Currently can't replace attribute certificates");
            }

            //
            // copy
            //
            CmsSignedData cms = new CmsSignedData(signedData);

            //
            // replace the certs and crls in the SignedData object
            //
            Asn1Set certs = null;

            try
            {
                Asn1Set asn1Set = CmsUtilities.CreateBerSetFromList(
                    CmsUtilities.GetCertificatesFromStore(x509Certs));

                if (asn1Set.Count != 0)
                {
                    certs = asn1Set;
                }
            }
            catch (X509StoreException e)
            {
                throw new CmsException("error getting certificates from store", e);
            }

            Asn1Set crls = null;

            try
            {
                Asn1Set asn1Set = CmsUtilities.CreateBerSetFromList(
                    CmsUtilities.GetCrlsFromStore(x509Crls));

                if (asn1Set.Count != 0)
                {
                    crls = asn1Set;
                }
            }
            catch (X509StoreException e)
            {
                throw new CmsException("error getting CRLs from store", e);
            }

            //
            // replace the CMS structure.
            //
            SignedData old = signedData.signedData;

            cms.signedData = new SignedData(
                old.DigestAlgorithms,
                old.EncapContentInfo,
                certs,
                crls,
                old.SignerInfos);

            //
            // replace the contentInfo with the new one
            //
            cms.contentInfo = new ContentInfo(cms.contentInfo.ContentType, cms.signedData);

            return(cms);
        }
            public override void Close()
            {
                _out.Close();
                _eiGen.Close();

                outer._digests.Clear();                    // clear the current preserved digest state

                if (outer._certs.Count > 0)
                {
                    Asn1Set certs = CmsUtilities.CreateBerSetFromList(outer._certs);

                    WriteToGenerator(_sigGen, new BerTaggedObject(false, 0, certs));
                }

                if (outer._crls.Count > 0)
                {
                    Asn1Set crls = CmsUtilities.CreateBerSetFromList(outer._crls);

                    WriteToGenerator(_sigGen, new BerTaggedObject(false, 1, crls));
                }

                //
                // Calculate the digest hashes
                //
                foreach (DictionaryEntry de in outer._messageDigests)
                {
                    outer._messageHashes.Add(de.Key, DigestUtilities.DoFinal((IDigest)de.Value));
                }

                // TODO If the digest OIDs for precalculated signers weren't mixed in with
                // the others, we could fill in outer._digests here, instead of SignerInf.ToSignerInfo

                //
                // add the precalculated SignerInfo objects.
                //
                Asn1EncodableVector signerInfos = new Asn1EncodableVector();

                foreach (SignerInformation signer in outer._signers)
                {
                    signerInfos.Add(signer.ToSignerInfo());
                }

                //
                // add the SignerInfo objects
                //
                foreach (SignerInf signer in outer._signerInfs)
                {
                    try
                    {
                        signerInfos.Add(signer.ToSignerInfo(_contentOID));
                    }
                    catch (IOException e)
                    {
                        throw new IOException("encoding error." + e);
                    }
                    catch (SignatureException e)
                    {
                        throw new IOException("error creating signature." + e);
                    }
                    catch (CertificateEncodingException e)
                    {
                        throw new IOException("error creating sid." + e);
                    }
                }

                WriteToGenerator(_sigGen, new DerSet(signerInfos));

                _sigGen.Close();
                _sGen.Close();
                base.Close();
            }
        /**
         * generate a signed object that for a CMS Signed Data
         * object  - if encapsulate is true a copy
         * of the message will be included in the signature. The content type
         * is set according to the OID represented by the string signedContentType.
         */
        public CmsSignedData Generate(
            // FIXME Avoid accessing more than once to support CmsProcessableInputStream
            ICmsTypedData content,
            bool encapsulate)
        {
            // TODO
            //        if (signerInfs.isEmpty())
            //        {
            //            /* RFC 3852 5.2
            //             * "In the degenerate case where there are no signers, the
            //             * EncapsulatedContentInfo value being "signed" is irrelevant.  In this
            //             * case, the content type within the EncapsulatedContentInfo value being
            //             * "signed" MUST be id-data (as defined in section 4), and the content
            //             * field of the EncapsulatedContentInfo value MUST be omitted."
            //             */
            //            if (encapsulate)
            //            {
            //                throw new IllegalArgumentException("no signers, encapsulate must be false");
            //            }
            //            if (!DATA.equals(eContentType))
            //            {
            //                throw new IllegalArgumentException("no signers, eContentType must be id-data");
            //            }
            //        }
            //
            //        if (!DATA.equals(eContentType))
            //        {
            //            /* RFC 3852 5.3
            //             * [The 'signedAttrs']...
            //             * field is optional, but it MUST be present if the content type of
            //             * the EncapsulatedContentInfo value being signed is not id-data.
            //             */
            //            // TODO signedAttrs must be present for all signers
            //        }

            Asn1EncodableVector digestAlgs  = new Asn1EncodableVector();
            Asn1EncodableVector signerInfos = new Asn1EncodableVector();

            _digests.Clear();  // clear the current preserved digest state

            //
            // add the precalculated SignerInfo objects.
            //
            for (IEnumerator it = _signers.GetEnumerator(); it.MoveNext();)
            {
                SignerInformation signer = (SignerInformation)it.Current;
                digestAlgs.Add(CmsUtilities.fixAlgID(signer.DigestAlgorithmID));

                // TODO Verify the content type and calculated digest match the precalculated SignerInfo
                signerInfos.Add(signer.ToAsn1Structure());
            }

            //
            // add the SignerInfo objects
            //
            DerObjectIdentifier contentTypeOID = content.ContentType;

            Asn1OctetString octs = null;

            if (content.GetContent() != null)
            {
                MemoryOutputStream bOut = null;

                if (encapsulate)
                {
                    bOut = new MemoryOutputStream();
                }

                Stream cOut = CmsUtilities.attachSignersToOutputStream(_signerGens, bOut);

                // Just in case it's unencapsulated and there are no signers!
                cOut = CmsUtilities.getSafeOutputStream(cOut);

                try
                {
                    content.Write(cOut);

                    cOut.Close();
                }
                catch (IOException e)
                {
                    throw new CmsException("data processing exception: " + e.Message, e);
                }

                if (encapsulate)
                {
                    octs = new BerOctetString(bOut.ToArray());
                }
            }

            for (IEnumerator it = _signerGens.GetEnumerator(); it.MoveNext();)
            {
                SignerInfoGenerator sGen = (SignerInfoGenerator)it.Current;
                SignerInfo          inf  = sGen.Generate(contentTypeOID);

                digestAlgs.Add(inf.DigestAlgorithm);
                signerInfos.Add(inf);

                byte[] calcDigest = sGen.getCalculatedDigest();

                if (calcDigest != null)
                {
                    _digests.Add(inf.DigestAlgorithm.Algorithm.Id, calcDigest);
                }
            }

            Asn1Set certificates = null;

            if (_certs.Count != 0)
            {
                certificates = CmsUtilities.CreateBerSetFromList(_certs);
            }

            Asn1Set certrevlist = null;

            if (_crls.Count != 0)
            {
                certrevlist = CmsUtilities.CreateBerSetFromList(_crls);
            }

            ContentInfo encInfo = new ContentInfo(contentTypeOID, octs);

            SignedData sd = new SignedData(
                new DerSet(digestAlgs),
                encInfo,
                certificates,
                certrevlist,
                new DerSet(signerInfos));

            ContentInfo contentInfo = new ContentInfo(
                CmsObjectIdentifiers.SignedData, sd);

            return(new CmsSignedData(content, contentInfo));
        }
Exemplo n.º 9
0
        public CmsSignedData Generate(string signedContentType, CmsProcessable content, bool encapsulate)
        {
            //IL_0113: Expected O, but got Unknown
            //IL_01b0: Unknown result type (might be due to invalid IL or missing references)
            //IL_01b7: Expected O, but got Unknown
            //IL_01c6: Expected O, but got Unknown
            Asn1EncodableVector asn1EncodableVector  = new Asn1EncodableVector();
            Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector();

            _digests.Clear();
            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)_signers).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    SignerInformation signerInformation = (SignerInformation)enumerator.get_Current();
                    asn1EncodableVector.Add(Helper.FixAlgID(signerInformation.DigestAlgorithmID));
                    asn1EncodableVector2.Add(signerInformation.ToSignerInfo());
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            DerObjectIdentifier contentType = ((signedContentType == null) ? null : new DerObjectIdentifier(signedContentType));

            enumerator = ((global::System.Collections.IEnumerable)signerInfs).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    SignerInf signerInf = (SignerInf)enumerator.get_Current();
                    try
                    {
                        asn1EncodableVector.Add(signerInf.DigestAlgorithmID);
                        asn1EncodableVector2.Add(signerInf.ToSignerInfo(contentType, content, rand));
                    }
                    catch (IOException val)
                    {
                        IOException e = val;
                        throw new CmsException("encoding error.", (global::System.Exception)(object) e);
                    }
                    catch (InvalidKeyException e2)
                    {
                        throw new CmsException("key inappropriate for signature.", e2);
                    }
                    catch (SignatureException e3)
                    {
                        throw new CmsException("error creating signature.", e3);
                    }
                    catch (CertificateEncodingException e4)
                    {
                        throw new CmsException("error creating sid.", e4);
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable2 = enumerator as global::System.IDisposable;
                if (disposable2 != null)
                {
                    disposable2.Dispose();
                }
            }
            Asn1Set certificates = null;

            if (((global::System.Collections.ICollection)_certs).get_Count() != 0)
            {
                certificates = CmsUtilities.CreateBerSetFromList(_certs);
            }
            Asn1Set crls = null;

            if (((global::System.Collections.ICollection)_crls).get_Count() != 0)
            {
                crls = CmsUtilities.CreateBerSetFromList(_crls);
            }
            Asn1OctetString content2 = null;

            if (encapsulate)
            {
                MemoryStream val2 = new MemoryStream();
                if (content != null)
                {
                    try
                    {
                        content.Write((Stream)(object)val2);
                    }
                    catch (IOException val3)
                    {
                        IOException e5 = val3;
                        throw new CmsException("encapsulation error.", (global::System.Exception)(object) e5);
                    }
                }
                content2 = new BerOctetString(val2.ToArray());
            }
            ContentInfo contentInfo = new ContentInfo(contentType, content2);
            SignedData  content3    = new SignedData(new DerSet(asn1EncodableVector), contentInfo, certificates, crls, new DerSet(asn1EncodableVector2));
            ContentInfo sigData     = new ContentInfo(CmsObjectIdentifiers.SignedData, content3);

            return(new CmsSignedData(content, sigData));
        }
        public CmsSignedData Generate(string signedContentType, CmsProcessable content, bool encapsulate)
        {
            Asn1EncodableVector asn1EncodableVector  = new Asn1EncodableVector(new Asn1Encodable[0]);
            Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector(new Asn1Encodable[0]);

            this._digests.Clear();
            foreach (SignerInformation signerInformation in this._signers)
            {
                asn1EncodableVector.Add(new Asn1Encodable[]
                {
                    CmsSignedDataGenerator.Helper.FixAlgID(signerInformation.DigestAlgorithmID)
                });
                asn1EncodableVector2.Add(new Asn1Encodable[]
                {
                    signerInformation.ToSignerInfo()
                });
            }
            DerObjectIdentifier contentType = (signedContentType == null) ? null : new DerObjectIdentifier(signedContentType);

            foreach (CmsSignedDataGenerator.SignerInf signerInf in this.signerInfs)
            {
                try
                {
                    asn1EncodableVector.Add(new Asn1Encodable[]
                    {
                        signerInf.DigestAlgorithmID
                    });
                    asn1EncodableVector2.Add(new Asn1Encodable[]
                    {
                        signerInf.ToSignerInfo(contentType, content, this.rand)
                    });
                }
                catch (IOException e)
                {
                    throw new CmsException("encoding error.", e);
                }
                catch (InvalidKeyException e2)
                {
                    throw new CmsException("key inappropriate for signature.", e2);
                }
                catch (SignatureException e3)
                {
                    throw new CmsException("error creating signature.", e3);
                }
                catch (CertificateEncodingException e4)
                {
                    throw new CmsException("error creating sid.", e4);
                }
            }
            Asn1Set certificates = null;

            if (this._certs.Count != 0)
            {
                certificates = CmsUtilities.CreateBerSetFromList(this._certs);
            }
            Asn1Set crls = null;

            if (this._crls.Count != 0)
            {
                crls = CmsUtilities.CreateBerSetFromList(this._crls);
            }
            Asn1OctetString content2 = null;

            if (encapsulate)
            {
                MemoryStream memoryStream = new MemoryStream();
                if (content != null)
                {
                    try
                    {
                        content.Write(memoryStream);
                    }
                    catch (IOException e5)
                    {
                        throw new CmsException("encapsulation error.", e5);
                    }
                }
                content2 = new BerOctetString(memoryStream.ToArray());
            }
            ContentInfo contentInfo = new ContentInfo(contentType, content2);
            SignedData  content3    = new SignedData(new DerSet(asn1EncodableVector), contentInfo, certificates, crls, new DerSet(asn1EncodableVector2));
            ContentInfo sigData     = new ContentInfo(CmsObjectIdentifiers.SignedData, content3);

            return(new CmsSignedData(content, sigData));
        }
            private void DoClose()
            {
                //IL_00b4: Unknown result type (might be due to invalid IL or missing references)
                //IL_00b9: Unknown result type (might be due to invalid IL or missing references)
                Platform.Dispose(_out);
                _eiGen.Close();
                outer._digests.Clear();
                if (((global::System.Collections.ICollection)outer._certs).get_Count() > 0)
                {
                    Asn1Set obj = CmsUtilities.CreateBerSetFromList(outer._certs);
                    WriteToGenerator(_sigGen, new BerTaggedObject(explicitly: false, 0, obj));
                }
                if (((global::System.Collections.ICollection)outer._crls).get_Count() > 0)
                {
                    Asn1Set obj2 = CmsUtilities.CreateBerSetFromList(outer._crls);
                    WriteToGenerator(_sigGen, new BerTaggedObject(explicitly: false, 1, obj2));
                }
                IDictionaryEnumerator enumerator = outer._messageDigests.GetEnumerator();

                try
                {
                    while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
                    {
                        DictionaryEntry val = (DictionaryEntry)((global::System.Collections.IEnumerator)enumerator).get_Current();
                        outer._messageHashes.Add(((DictionaryEntry)(ref val)).get_Key(), (object)DigestUtilities.DoFinal((IDigest)((DictionaryEntry)(ref val)).get_Value()));
                    }
                }
                finally
                {
                    (enumerator as global::System.IDisposable)?.Dispose();
                }
                Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();

                global::System.Collections.IEnumerator enumerator2 = ((global::System.Collections.IEnumerable)outer._signerInfs).GetEnumerator();
                try
                {
                    while (enumerator2.MoveNext())
                    {
                        DigestAndSignerInfoGeneratorHolder digestAndSignerInfoGeneratorHolder = (DigestAndSignerInfoGeneratorHolder)enumerator2.get_Current();
                        AlgorithmIdentifier digestAlgorithm = digestAndSignerInfoGeneratorHolder.DigestAlgorithm;
                        byte[] array = (byte[])outer._messageHashes.get_Item((object)Helper.GetDigestAlgName(digestAndSignerInfoGeneratorHolder.digestOID));
                        outer._digests.set_Item((object)digestAndSignerInfoGeneratorHolder.digestOID, ((global::System.Array)array).Clone());
                        asn1EncodableVector.Add(digestAndSignerInfoGeneratorHolder.signerInf.Generate(_contentOID, digestAlgorithm, array));
                    }
                }
                finally
                {
                    global::System.IDisposable disposable = enumerator2 as global::System.IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                enumerator2 = ((global::System.Collections.IEnumerable)outer._signers).GetEnumerator();
                try
                {
                    while (enumerator2.MoveNext())
                    {
                        SignerInformation signerInformation = (SignerInformation)enumerator2.get_Current();
                        asn1EncodableVector.Add(signerInformation.ToSignerInfo());
                    }
                }
                finally
                {
                    global::System.IDisposable disposable2 = enumerator2 as global::System.IDisposable;
                    if (disposable2 != null)
                    {
                        disposable2.Dispose();
                    }
                }
                WriteToGenerator(_sigGen, new DerSet(asn1EncodableVector));
                _sigGen.Close();
                _sGen.Close();
            }