title: How to sign X509 certificate requests by using java API?
body: <p>My java program should sign received X509 certificate requests by using own key.
  Certificate requests are in PEM format. The key/certificate for signing is in the local java key store.</p>
  
  <p>I have seek suitable classes from <code>java.security</code> package. But without success.</p>
  
  <p>What classes of Java API should be used for signing X509 certificates?</p>
  
  <p>I can convert PEM to DER, but decoding of DER causes problems.
  I have tried the following:</p>
  
  <pre><code>BufferedInputStream  bis  = new BufferedInputStream(new ByteArrayInputStream(derReq));          
  CertificateFactory certFact = CertificateFactory.getInstance("X.509");          
  java.security.cert.Certificate cert = certFact.generateCertificate(bis);
  </code></pre>
  
  <p>And</p>
  
  <pre><code>javax.security.cert.X509Certificate cer = X509Certificate.getInstance(derReq);
  </code></pre>
  
  <p>Both will cause the following exception:</p>
  
  <pre><code>javax.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Empty input
  </code></pre>
  
  <p>So, seems that those are only for signed certificates, and not for X509 certificate requests.</p>