title: Use keytool with Runtime.getRuntime().exec() under Linux
body: <p>I'd like to create a self-signed certificate by invoking keytool in my java script. Here is a simplified version of my code which includes the problem I have: </p>
  
  <pre><code>    public class Tester {
          public static void main(String[] args) {   
              String[] cmd = {   
                  "/bin/sh",  
                  "-c",  
                  "keytool",  
                  "-genkey",   
                  "-dname",  
                  "\"C=US,CN=CU,L=ABC,O=ABC_Univ,OU=ABC_Pro\"",  
                  "-keysize",  
                  "1024",  
                  "-alias",  
                  "testkeypairs",
                  "-keyalg",  
                  "RSA",  
                  "-sigalg",   
                  "SHA1withRSA",  
                  "-keystore",     
                  "testkeystore",  
                  "-storepass",  
                  "abcdef",  
                  "-keypass",  
                  "abcdef"  
              }    
              Process testProc = Runtime.getRuntime().exec(cmd);  
  }  
  </code></pre>
  
  <p>There is no error when I ran it. But it did not give me the keystore. My questions are:</p>
  
  <ol>
  <li><p>The certificate generated by keytool is not considered as the "subprocess's output" which needs to be fed to the parent process using <code>getinputstream()</code>, is it? </p></li>
  <li><p>If it is, I also tried the <code>getinputstream()</code> thing as discussed in the following post, </p></li>
  </ol>
  
  <p><a href="https://stackoverflow.com/questions/8308148/keytool-usage-with-runtime-getruntime-exec-under-linux">Keytool usage with Runtime.getRuntime().exec() under Linux</a></p>
  
  <p>the program just got stuck and seems to never stop.</p>
  
  <ol start="3">
  <li>Is there any other ways to create self-signed certificate using java program? </li>
  </ol>
  
  <p>I am a newbie in Java and English is not my first language. I hope I have expressed my question clearly.</p>