Whoops! This method only takes an InputStream on my LOCAL machine. :-$
PKCS8Key.decrypt( "DES", "CBC", dk, false, null, fin ); You'll need to replace that line with: byte[] bytes = Util.streamToBytes( fin ); PKCS8Key.decrypt( "DES", "CBC", dk, false, null, bytes ); yours, Julius On 12/5/06, Julius Davies <[EMAIL PROTECTED]> wrote:
Hi, Marc, If you download the "not-yet-commons-ssl.jar" I'm working on, you can decrypt your file with the Java code I've included below. I tested using Sun Java 1.4.2. Notice the password in the example: char[] pwd = "secret".toCharArray(); http://juliusdavies.ca/commons-ssl/download.html Unfortunately the jar file isn't properly setup to stream the decryption. Normally I'm decrypting PKCS #8 RSA Private Keys, and so I always read them into byte[] arrays. If you're decrypting big stuff, this code probably uses a lot of memory. Hopefully this will help get you started! import org.apache.commons.ssl.Util; import org.apache.commons.ssl.DerivedKey; import org.apache.commons.ssl.PKCS8Key; public static void main( String[] args ) throws Exception { FileInputStream fin = new FileInputStream( args[ 0 ] ); byte[] saltLine = new byte[ 16 ]; int[] status = Util.fill( saltLine, 0, fin ); if ( status[ 0 ] != saltLine.length ) { throw new IOException( "couldn't read salt-line from OpenSSL file" ); } byte[] salt = new byte[ 8 ]; System.arraycopy( saltLine, 8, salt, 0, 8 ); char[] pwd = "secret".toCharArray(); byte[] pass = new byte[pwd.length]; for ( int i = 0; i < pass.length; i++ ) { pass[ i ] = (byte) pwd[ i ]; } MessageDigest md5 = MessageDigest.getInstance( "MD5" ); int keySize = 64; DerivedKey dk = PKCS8Key.deriveKeyOpenSSL( pass, salt, keySize, md5 ); PKCS8Key.DecryptResult dr = PKCS8Key.decrypt( "DES", "CBC", dk, false, null, fin ); System.out.println( new String( dr.bytes ) ); }
-- yours, Julius Davies 416-652-0183 http://juliusdavies.ca/