ToSignerInfo() public method

public ToSignerInfo ( ) : SignerInfo
return SignerInfo
        public static SignerInformation AddCounterSigners(SignerInformation signerInformation, SignerInformationStore counterSigners)
        {
            Org.BouncyCastle.Asn1.Cms.SignerInfo     signerInfo         = signerInformation.info;
            Org.BouncyCastle.Asn1.Cms.AttributeTable unsignedAttributes = signerInformation.UnsignedAttributes;
            Asn1EncodableVector asn1EncodableVector  = ((unsignedAttributes == null) ? new Asn1EncodableVector() : unsignedAttributes.ToAsn1EncodableVector());
            Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector();

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)counterSigners.GetSigners()).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    SignerInformation signerInformation2 = (SignerInformation)enumerator.get_Current();
                    asn1EncodableVector2.Add(signerInformation2.ToSignerInfo());
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            asn1EncodableVector.Add(new Attribute(CmsAttributes.CounterSignature, new DerSet(asn1EncodableVector2)));
            return(new SignerInformation(new Org.BouncyCastle.Asn1.Cms.SignerInfo(signerInfo.SignerID, signerInfo.DigestAlgorithm, signerInfo.AuthenticatedAttributes, signerInfo.DigestEncryptionAlgorithm, signerInfo.EncryptedDigest, new DerSet(asn1EncodableVector)), signerInformation.contentType, signerInformation.content, null));
        }
 private bool CheckForVersion3(global::System.Collections.IList signerInfos)
 {
     global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)signerInfos).GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             SignerInformation signerInformation = (SignerInformation)enumerator.get_Current();
             SignerInfo        instance          = SignerInfo.GetInstance(signerInformation.ToSignerInfo());
             if (instance.Version.Value.IntValue == 3)
             {
                 return(true);
             }
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return(false);
 }
Example #3
0
        public static CmsSignedData ReplaceSigners(CmsSignedData signedData, SignerInformationStore signerInformationStore)
        {
            CmsSignedData cmsSignedData = new CmsSignedData(signedData);

            cmsSignedData.signerInfoStore = signerInformationStore;
            Asn1EncodableVector asn1EncodableVector  = new Asn1EncodableVector();
            Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector();

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)signerInformationStore.GetSigners()).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();
                }
            }
            Asn1Set      asn1Set      = new DerSet(asn1EncodableVector);
            Asn1Set      asn1Set2     = new DerSet(asn1EncodableVector2);
            Asn1Sequence asn1Sequence = (Asn1Sequence)signedData.signedData.ToAsn1Object();

            asn1EncodableVector2 = new Asn1EncodableVector(asn1Sequence[0], asn1Set);
            for (int i = 2; i != asn1Sequence.Count - 1; i++)
            {
                asn1EncodableVector2.Add(asn1Sequence[i]);
            }
            asn1EncodableVector2.Add(asn1Set2);
            cmsSignedData.signedData  = SignedData.GetInstance(new BerSequence(asn1EncodableVector2));
            cmsSignedData.contentInfo = new ContentInfo(cmsSignedData.contentInfo.ContentType, cmsSignedData.signedData);
            return(cmsSignedData);
        }
Example #4
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));
        }
            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();
            }