Search this site
|
Reading encrypted archives with the Java Arcmexer libraryThe Arcmexer library allows you to read encrypted ZIP files from Java. The Java code for reading encrypted ZIP files is essentially the same as reading from an archive generally, but you need to supply the password for the archive or for individual files. The current version of the library will read from ZIP files encrypted either with the traditional (insecure) PKZIP encryption, or with the more secure 128-bit AES encryption method. Other encryption methods are not currently supported, but may be added in future versions. Case 1: all files encrypted with the same passwordIf all entries in the encrypted ZIP file have the same password, then you need only supply the password once. Call setDefaultPassword() on the ArchiveReader: ArchiveReader r = ArchiveReader.getReader(f); r.setDefaultPassword("ThePassword"); ... read entries as before If entries in the same ZIP are not encrypted, then the password will be ignored for those files, and the unencrypted files read as normal. Case 2: files encrypted with different passwordsIf one or more entries are encrypted with a different password, then you can specify a password for an individual entry by calling setPassword() on the ArchiveEntry object: import com.javamex.arcmexer.*; ArchiveReader r = ArchiveReader.getReader(f); try { ArchiveEntry entry; while ((entry = r.nextEntry()) != null) { String filename = entry.getFilename(); if ("special.txt".equals(filename)) { entry.setPassword("SpecialPassword"); } InputStream in = entry.getInputStream(); // ... read from in } } finally { r.close(); } Note that you can still set a default password on the ArchiveReader, which will then be used for encrypted entries where you don't specify an entry-specific password. Password recoveryOn the next page, we look at how to perform password recovery on AES-encrypted ZIPs using the Arcmexer library. Password recovery is an issue that sometimes comes up in data recovery applications. Copyright © Javamex UK 2009. All rights reserved. Please note that the software provided on this site is provided "as is". |