title: Fail to Generate Root Certification thorough JSP
body: <p>I'm now working on creating PKCS10 root certificate by using the bouncy castle library.</p>
  
  <p>Thus, I import the bouncy castle library with (RootCertGenerator.java) which is correctly working on pure java environment(all I've done with the RootCertGenerator.java is modifying a main() method to execute(),, rename the method)</p>
  
  <p>However, after execute the generateRooteCert.jsp, it shows tomcat error as shown on the bottom part of the page. some say that it may be solved by include mail.jar on the build path, but it does not work.</p>
  
  <p>---generateRooteCert.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=EUC-KR"%&gt;
  &lt;%@ page import="java.sql.DriverManager" %&gt;
  &lt;%@ page import="java.sql.Connection" %&gt;
  &lt;%@ page import="java.sql.PreparedStatement" %&gt;
  &lt;%@ page import="java.sql.Statement" %&gt;
  &lt;%@ page import="java.sql.SQLException" %&gt;
  &lt;%@ page import="java.sql.ResultSet" %&gt;
  &lt;%@ page import="myPackage.Utils" %&gt;
  &lt;%@ page import="myPackage.RootCertGenerator" %&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"&gt;
  &lt;title&gt;Make root Certificate&lt;/title&gt;
  &lt;/head&gt;
  &lt;% 
  RootCertGenerator.execute();
  %&gt;
  &lt;body&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>---RootCertGenerator.java
      package myPackage;</p>
  
  <pre><code>import java.io.FileOutputStream;
  import java.io.FileWriter;
  import java.io.OutputStreamWriter;
  import java.math.BigInteger;
  import java.security.*;
  import java.security.cert.X509Certificate;
  import java.util.Date;
  import javax.security.auth.x500.X500Principal;
  import org.bouncycastle.openssl.PEMWriter;
  import org.bouncycastle.x509.X509V1CertificateGenerator;
  
  public class RootCertGenerator
  {
  public static X509Certificate generateV1Certificate(KeyPair pair)
  throws InvalidKeyException, NoSuchProviderException, SignatureException
  {
   // generate the certificate
  X509V1CertificateGenerator  certGen = new X509V1CertificateGenerator();
  certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
  certGen.setIssuerDN(new X500Principal("CN=Test Certificate"));
  certGen.setNotBefore(new Date(System.currentTimeMillis() - (7 * 24 * 60 * 60 * 1000))); 
  certGen.setNotAfter(new Date(System.currentTimeMillis() + (7 * 24 * 60 * 60 * 1000)));
  certGen.setSubjectDN(new X500Principal("CN=Test Certificate"));
  certGen.setPublicKey(pair.getPublic());
  certGen.setSignatureAlgorithm("SHA256WithRSAEncryption");
  return certGen.generateX509Certificate(pair.getPrivate(), "BC");
  }
  
  //////////added by jeon
  public static void pemEncodeToFile(String filename, Object obj, char[] password) throws
  Exception{
  PEMWriter pw = new PEMWriter(new FileWriter(filename));
  if (password != null &amp;&amp; password.length &gt; 0) {
  pw.writeObject(obj, "DESEDE", password, new SecureRandom());
  } else {
  pw.writeObject(obj);
  }
  pw.flush();
  pw.close();
  }
  //////////added by jeon
  
  public static void execute() throws Exception
  {
  // create the keys
  KeyPair          pair = Utils.generateRSAKeyPair();
  
  ////////////////////writing root certificate
  PEMWriter pemWrt = new PEMWriter(new OutputStreamWriter(System.out));
  pemWrt.writeObject(cert);
  pemEncodeToFile("rootCertificate.cer", cert, null);
  pemWrt.flush();
  pemWrt.close();
  /////////////////writing private key
  PEMWriter pemWrt1 = new PEMWriter(new OutputStreamWriter(System.out));
  pemWrt1.writeObject(pair.getPrivate());
  pemEncodeToFile("rootPrivate.key", pair.getPrivate(), null);
  pemWrt1.flush();
  pemWrt1.close();
  
  /////////////////writing public key
  PEMWriter pemWrt2 = new PEMWriter(new OutputStreamWriter(System.out));
  pemWrt2.writeObject(pair.getPublic());
  pemEncodeToFile("rootPublic.key", pair.getPublic(), null);
  pemWrt2.flush();
  pemWrt2.close();
  // show some basic validation
  cert.checkValidity(new Date());
  cert.verify(cert.getPublicKey());        
  System.out.println("valid certificate generated");
  }
  }
  </code></pre>
  
  <p>And error message is</p>
  
  <pre><code>org.apache.jasper.JasperException:
  javax.servlet.ServletException:
  java.security.NoSuchProviderException: no such provider: BC
  </code></pre>
  
  <p>I feel that the TOMCAT failed to load the bouncycastle provider even though my system</p>
  
  <p>/jre/lib/security/java.security contains the bouncycaslte information.</p>
  
  <p>what should I do?</p>