Thank you Julius Davies! for not-yet-commons-ssl which does exactly what I was looking for
import org.apache.commons.io.IOUtils;
import org.apache.commons.ssl.OpenSSL;
import java.io.File;
import java.io.FileOutputStream;
public class Foo
{
public static void main(String[] args) throws Exception
{
File f = new File("/tmp/foo");
FileOutputStream fout = new FileOutputStream(f);
fout.write(OpenSSL.encrypt("aes256",
"secret".toCharArray(),
"hello world\n".getBytes("UTF-8")));
fout.close();
Process p = Runtime.getRuntime()
.exec("openssl enc -pass pass:secret -d -aes256 -a -in /tmp/foo");
System.out.print(IOUtils.toString(p.getInputStream()));
}
}
Woo hoo!
writebacks...
You're very welcome!!!
There's a bug in the OpenSSL.decrypt() code that causes it to *ahem* not decrypt some base64 data (raw binary is fine). Looks like you're just using encrypt(), so you'll be okay. A new release (0.3.10) with a fix will be out soon (within 3 - 4 days).
ps. here's a note on the mailing-list about the bug: http://lists.juliusdavies.ca/pipermail/not-yet-commons-ssl-juliusdavies.ca/2008-January/000098.html
comment...