0

I would like to unzip and decrypt a zip-encrypted file "Encrypted.zip" using Apache Camel.

The encryption has been done as part of the zipping process, with a simple password, so this is a one-step process, not x.zip.pgp or x.pgp.zip. Zip encryption seems to be AES.

ZipFileDataFormat does not seem to have a password option and Crypto seems to be oriented towards key-files and probably not suited for multiple files.

I have a solution that wraps a call to 7zip.exe, but I am looking for a more efficient and Camel-native way of solving the problem.

Jan Larsen
  • 831
  • 6
  • 13

1 Answers1

1

A Google search led me to Martin Matula's blog: http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/

He has written an InputStream in Java which does what you seem to request:

public class ZipDecryptInputStream extends InputStream {

    public ZipDecryptInputStream(InputStream stream, String password) {
        this.delegate = stream;
        this.password = password;
    }

    ...
}

You should also take a look at Apache Commons Compress which I also believe supports reading of encrypted zipfiles.

Whether or not this is entangled in Camel is probably not so relevant for the problem at hand. Once you have a class, which can read an encrypted zipfile, you can create a custom processor or endpoint in Camel.

tbsalling
  • 4,477
  • 4
  • 30
  • 51
  • 1
    I did find the Matula blog, but it states: Only the “Traditional PKWARE Encryption” is supported. I am looking at http://www.lingala.net/zip4j/ but will check out AC Compresss. Thanks. – Jan Larsen Aug 20 '18 at 11:15
  • 1
    "The ZIP specification allows for various other compression algorithms and also supports several different ways of encrypting archive contents. Neither of those methods is currently supported by Commons Compress and any such entry can not be extracted by the archiving code" – Jan Larsen Aug 20 '18 at 11:21
  • @JanLarsen: Yes, this is useless, except perhaps for the structure of the `ZipDecryptInputStream`. – President James K. Polk Aug 20 '18 at 13:28