CertificateFactory cf;  try { cf = CertificateFactory.getInstance("X.509", provider); } catch (CertificateException ex) { throw new CMSException("can't get certificate factory.", ex); }
    protected CertStore createCertStore(        String type,        String provider,        ASN1Set certSet,        ASN1Set crlSet)        throws NoSuchProviderException, CMSException, NoSuchAlgorithmException    {        List certsAndcrls = new ArrayList();        CertificateFactory cf;        try        {            cf = CertificateFactory.getInstance("X.509", provider);        }        catch (CertificateException ex)        {            throw new CMSException("can't get certificate factory.", ex);        }        //        // load the certificates and revocation lists if we have any        //        if (certSet != null)        {            Enumeration e = certSet.getObjects();            while (e.hasMoreElements())            {                try                {                    DERObject obj = ((DEREncodable)e.nextElement()).getDERObject();                    if (obj instanceof ASN1Sequence)                    {                        certsAndcrls.add(cf.generateCertificate(                            new ByteArrayInputStream(obj.getEncoded())));                    }                }                catch (IOException ex)                {                    throw new CMSException(                            "can't re-encode certificate!", ex);                }                catch (CertificateException ex)                {                    throw new CMSException(                            "can't re-encode certificate!", ex);                }            }        }        if (crlSet != null)        {            Enumeration e = crlSet.getObjects();            while (e.hasMoreElements())            {                try                {                    DERObject obj = ((DEREncodable)e.nextElement()).getDERObject();                    certsAndcrls.add(cf.generateCRL(                        new ByteArrayInputStream(obj.getEncoded())));                }                catch (IOException ex)                {                    throw new CMSException("can't re-encode CRL!", ex);                }                catch (CRLException ex)                {                    throw new CMSException("can't re-encode CRL!", ex);                }            }        }        try        {            return CertStore.getInstance(type, new CollectionCertStoreParameters(certsAndcrls), provider);        }        catch (InvalidAlgorithmParameterException e)        {            throw new CMSException("can't setup the CertStore", e);        }    }