Execute an openssl command from a Java program
Hello,
I need to execute an openssl command from a java program to decrypt a password. i have tried the following:
Process p = Runtime.getRuntime().exec("echo " + encodedPassword + " | openssl aes-256-cbc -salt -a -d -pass pass:" + passphared);
BufferedReader reader;
// Command completed successfully
reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = null;
while ( (s = reader.readLine()) != null ) {
System.out.println(s);
}
I got a IO exception with the following message: CreateProcess: echo U2FsdGVkX19fYZhqxtOQXmkcJTwqCX8YrKEm0w7ISjo= | openssl aes-256-cbc -a -d -pass pass:coucou error=2
I do not know what's error=2. I replace the openssl command by the ping command and in that case it works well. Any idea will be more than welcome.
reader.close();
[872 byte] By [
marlysaa] at [2007-10-2 17:19:49]

> I changed the command to:
>
> Process p = Runtime.getRuntime().exec("openssl
> aes-256-cbc -a -d -pass pass:" + passphrase + " <<EOF
> " + encodedPassword + " EOF");
>
> And it works better.
except that I can not catch the command output ....
On Unix there is the possibility to open /dev/tty, that is, the controlling terminal even if stdin was redirected. Especially passwords are taken this way. This is way stdin-magic does not forcibly work with telnet, ssh andf the like.
> Your reader is only reading from System.out, not
> System.err. Might be one reason. And might openssl
> (which I don't know) be waiting for input?
reading the error stream, I discovered that the problem was <<. cmd.exe does not accept such a command. I have decided so to use an input file for my command. Now I am getting the error: error reading input file from the java program and also from the command line....