title: CSR generation using java or BouncyCastle without using Private key
body: <p>Want to create a CSR file in java, when the private/public key pair are getting generated in HSM(Hardware Security Module).</p>
  
  <p>On trying out the examples in Bouncy Castle, the generation of CSR requires both the private key and public key.As the generation of keys is happening in HSM, i have only the <strong>public key</strong> and the <strong>private key sham object</strong>.
  Can i generate CSR in java without having the private key?</p>
  
  <p>Please find the code sample i was trying.</p>
  
  <pre><code> KeyPair pair = generateKeyPair();
      PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(
          new X500Principal("CN=Requested Test Certificate"), pair.getPublic());
      JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withRSA");
      ContentSigner signer = csBuilder.build(pair.getPrivate());
      PKCS10CertificationRequest csr = p10Builder.build(signer);
  </code></pre>
  
  <p>I am pretty new to HSM, and any input or reference will be helpful.</p>