2

There's a relatively new zip filesystem provider that's a supported part of the NIO2 library in JDK7 and above.

I specifically need it to support the java.nio.file.FileSystem class.

Is it compatible with encrypted .zip files and if so, how do you specify a decryption key?


very similar to this other question but it's on Android; I don't need to worry about Android in my case, or support any existing code.

Community
  • 1
  • 1
Jason S
  • 184,598
  • 164
  • 608
  • 970
  • May I humbly recommend the [Apache VFS](https://commons.apache.org/proper/commons-vfs/) package? – PaulProgrammer Oct 20 '15 at 14:59
  • re: Apache VFS: it looks very interesting, but I need it to `support java.nio.file.Filesystem`, and it looks like VFS does not; I guess Apache did their own thing before NIO2. – Jason S Oct 20 '15 at 15:23

1 Answers1

2

If you trie to mount an encrypted zip file you get the error:

Exception in thread "main" java.util.zip.ZipError: invalid CEN header (encrypted entry)
    at com.sun.nio.zipfs.ZipFileSystem.zerror(ZipFileSystem.java:1605)
    at com.sun.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1064)
    at com.sun.nio.zipfs.ZipFileSystem.<init>(ZipFileSystem.java:130)
    at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:139)
    at java.nio.file.FileSystems.newFileSystem(FileSystems.java:390)    

The causing line is

if ((ZipConstants.CENFLG(arrayOfByte1, i) & 0x1) != 0)
    zerror("invalid CEN header (encrypted entry)");

So the exception is thrown for every encrypted entry. Therefore the ZipFileSystem does not support encrypted files at the moment (Java 8).

wero
  • 32,544
  • 3
  • 59
  • 84