title: Java code to generate private key and self signed certificate
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/925377/generate-certificates-public-and-private-keys-with-java">Generate certificates, public and private keys with Java</a>  </p>
  </blockquote>
  
  
  
  <p>I want to generate private key and self signed certificate using Java code and export it into files. When I searched through net I am getting details only achieving through openssl or keytool commands, but not through java code. I would like not to use any third party library.</p>
  
  <p>Below are the commands which creates key and self signed certificate, which I want to do the same using java code.</p>
  
  <pre><code>       openssl req -new -text -out server.req
  
         openssl rsa -in privkey.pem -out server.key
  
         openssl req -x509 -in server.req -text -key server.key -out server.crt
  </code></pre>
  
  <p>Any kind of help or suggestion will be really appreciated.</p>