class OcspClientBouncyCastle implements OcspClient {

    /**
     * root certificate
     */
    private final X509Certificate rootCert;
    /**
     * check certificate
     */
    private final X509Certificate checkCert;
    /**
     * OCSP URL
     */
    private final String url;
    /**
     * HTTP proxy used to access the OCSP URL
     */
    private Proxy proxy;

    /**
     * Creates an instance of an OcspClient that will be using BouncyCastle.
     *
     * @param checkCert the check certificate
     * @param rootCert  the root certificate
     * @param url       the OCSP URL
     */
    public OcspClientBouncyCastle(X509Certificate checkCert,
            X509Certificate rootCert, String url) {
        this.checkCert = checkCert;
        this.rootCert = rootCert;
        this.url = url;
    }

    /**
     * Generates an OCSP request using BouncyCastle.
     *
     * @param issuerCert   certificate of the issues
     * @param serialNumber serial number
     * @return an OCSP request
     * @throws OCSPException
     * @throws IOException
     */
    private static OCSPReq generateOCSPRequest(X509Certificate issuerCert,
            BigInteger serialNumber) throws OCSPException, IOException,
            OperatorCreationException, CertificateEncodingException {<FILL_FUNCTION_BODY>}

    /**
     * @return a byte array
     * @see com.lowagie.text.pdf.OcspClient
     */
    @Override
    public byte[] getEncoded() {
        try {
            OCSPReq request = generateOCSPRequest(rootCert,
                    checkCert.getSerialNumber());
            byte[] array = request.getEncoded();
            URL urlt = new URL(url);
            Proxy tmpProxy = proxy == null ? Proxy.NO_PROXY : proxy;
            HttpURLConnection con = (HttpURLConnection) urlt.openConnection(tmpProxy);
            con.setRequestProperty("Content-Type", "application/ocsp-request");
            con.setRequestProperty("Accept", "application/ocsp-response");
            con.setDoOutput(true);
            OutputStream out = con.getOutputStream();
            DataOutputStream dataOut = new DataOutputStream(new BufferedOutputStream(
                    out));
            dataOut.write(array);
            dataOut.flush();
            dataOut.close();
            if (con.getResponseCode() / 100 != 2) {
                throw new IOException(MessageLocalization.getComposedMessage(
                        "invalid.http.response.1", con.getResponseCode()));
            }
            // Get Response
            InputStream in = (InputStream) con.getContent();
            OCSPResp ocspResponse = new OCSPResp(in);

            if (ocspResponse.getStatus() != 0) {
                throw new IOException(MessageLocalization.getComposedMessage(
                        "invalid.status.1", ocspResponse.getStatus()));
            }
            BasicOCSPResp basicResponse = (BasicOCSPResp) ocspResponse
                    .getResponseObject();
            if (basicResponse != null) {
                SingleResp[] responses = basicResponse.getResponses();
                if (responses.length == 1) {
                    SingleResp resp = responses[0];
                    Object status = resp.getCertStatus();
                    if (status == null) {
                        return basicResponse.getEncoded();
                    } else if (status instanceof org.bouncycastle.cert.ocsp.RevokedStatus) {
                        throw new IOException(
                                MessageLocalization
                                        .getComposedMessage("ocsp.status.is.revoked"));
                    } else {
                        throw new IOException(
                                MessageLocalization
                                        .getComposedMessage("ocsp.status.is.unknown"));
                    }
                }
            }
        } catch (Exception ex) {
            throw new ExceptionConverter(ex);
        }
        return null;
    }

    /**
     * Returns Proxy object used for URL connections.
     *
     * @return configured proxy
     */
    public Proxy getProxy() {
        return proxy;
    }

    /**
     * Sets Proxy which will be used for URL connection.
     *
     * @param aProxy Proxy to set
     */
    public void setProxy(final Proxy aProxy) {
        this.proxy = aProxy;
    }
}

        // Add provider BC
        Provider prov = new org.bouncycastle.jce.provider.BouncyCastleProvider();
        Security.addProvider(prov);

        // Generate the id for the certificate we are looking for
        // OJO... Modificacion de
        // Felix--------------------------------------------------
        // CertificateID id = new CertificateID(CertificateID.HASH_SHA1, issuerCert,
        // serialNumber);
        // Example from
        // http://grepcode.com/file/repo1.maven.org/maven2/org.bouncycastle/bcmail-jdk16/1.46/org/bouncycastle/cert/ocsp/test/OCSPTest.java
        DigestCalculatorProvider digCalcProv = new JcaDigestCalculatorProviderBuilder()
                .setProvider(prov).build();

        CertificateID id = new CertificateID(
                digCalcProv.get(CertificateID.HASH_SHA1), new JcaX509CertificateHolder(
                issuerCert), serialNumber);

        // basic request generation with nonce
        OCSPReqBuilder gen = new OCSPReqBuilder();

        gen.addRequest(id);

        // create details for nonce extension
        // Vector oids = new Vector();
        // Vector values = new Vector();
        // oids.add(OCSPObjectIdentifiers.id_pkix_ocsp_nonce);
        // values.add(new X509Extension(false, new DEROctetString(new
        // DEROctetString(PdfEncryption.createDocumentId()).getEncoded())));
        // gen.setRequestExtensions(new X509Extensions(oids, values));

        // Add nonce extension
        ExtensionsGenerator extGen = new ExtensionsGenerator();
        byte[] nonce = new byte[16];
        Random rand = new Random();
        rand.nextBytes(nonce);

        extGen.addExtension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false,
                new DEROctetString(nonce));
        gen.setRequestExtensions(extGen.generate());

        // Build request
        return gen.build();
        // ******************************************************************************
    
<no_super_class>