-1
ProcessBuilder process3 = new ProcessBuilder(
           "openssl" ,
                        "req",
                        "-new",
                        "-key",
                        "-",
                        "-subj",
                        "/C=IN/ST=TamilNadu/L=Chennai/O=Inspoworks Private Ltd/OU=IT solutions/CN=com.radnus.com/[email protected]",
                        "-out","-");

   Process p3 = process3.start();

   try(BufferedOutputStream bos1 = new BufferedOutputStream(p3.getOutputStream())){
       bos1.write(privatekey.getBytes());
       bos1.flush();

   }

   String csr1 = readOutput(p3.getInputStream());
   System.out.println(csr1);
    exitcode = p3.waitFor();
    if (exitcode != 0) {
        System.err.println(exitcode);
        System.err.println(readOutput(p3.getErrorStream()));
    }
    System.out.println(csr1);

}
 //general method to read terminal output
public static String readOutput(InputStream inputstream) throws IOException {
    StringBuilder sb = new StringBuilder();
    try (InputStreamReader reader = new InputStreamReader(inputstream)) {
        int ch;
        while ((ch = reader.read()) != -1) {
            sb.append((char)ch);
        }
    }

    return sb.toString();
}

Facing error while creating CSR certificate using Open ssl inside a java code using process builder, i can able to create private key , public key but cant able to create CSR using private key

New contributor
Sundar D is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • 4
    What error are you getting? If you have a stack trace, please edit your question and post it. Commented 2 days ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.