Brian's Waste of Time

Fri, 07 Dec 2007

Re: JCE and OpenSSL

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...

Julius Davies


You're very welcome!!!

Julius Davies


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).

Julius Davies


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...

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Spam Guard, translate l33t to English: (hint, it's an Australian animal, plural form)
Comments:
Save my Name and URL/Email for next time