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:
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); } There is no error when I ran it. But it did not give me the keystore. My questions are:
The certificate generated by keytool is not considered as the "subprocess's output" which needs to be fed to the parent process using
getinputstream(), is it?If it is, I also tried the
getinputstream()thing as discussed in the following post,
Keytool usage with Runtime.getRuntime().exec() under Linux
the program just got stuck and seems to never stop.
- Is there any other ways to create self-signed certificate using java program?
I am a newbie in Java and English is not my first language. I hope I have expressed my question clearly.
execto call the keytool binary, try calling the Keystore creation code yourself, programatically. stackoverflow.com/questions/5312559/…