0

I have used zip4j to zip certain files. It is able to properly zip and while extracting it asks for password also. So far so go. Now problems I am facing

  1. After encrypting with password you can see the file name if you open by 7zip [is there any way to hise this?]
  2. You can add new files to the zip, simply open it by 7zip and drag a new file it will be add, and allows to extract also particularly that file without password. [ need to disable this?]

My requirement is to lock some files and user should not able to manipulate with the zip . (point 1 is ignore able also )

I there any other was then this ?

final ZipFile zipFile = new ZipFile(outputFile);

final ArrayList filesToAdd = new ArrayList();
for (final String file : fileList) {
    filesToAdd.add(new File(file));
}
// Initiate Zip Parameters
final ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to
                                                          // deflate compressio
// Set the compression level.
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
parameters.setEncryptFiles(true);
// Set the encryption method to Standard Zip Encryption
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
// Set password
parameters.setPassword(password);

zipFile.addFiles(filesToAdd, parameters);
Pranoy Sarkar
  • 1,965
  • 14
  • 31
  • According to [this](https://security.stackexchange.com/questions/35818/are-password-protected-zip-files-secure) it's not possible with zip files. – Sascha May 23 '19 at 11:59
  • If you want to protect your file from reading you could [password-encrypt the resulting file](https://stackoverflow.com/questions/13673556/using-password-based-encryption-on-a-file-in-java) (in a second stage after the zipping). That would break the readability by other zip programs. – Sascha May 23 '19 at 12:03

1 Answers1

1

The feature you are looking for is called "Strong Encryption" as per Zip format specification. Section "7.0 Strong Encryption Specification" in the link covers this encryption standard. This technique also encrypts the zip header information, therefore making the zip file impossible to modify without the password. However, this feature is proprietary and patent protected. AFAIK, libraries/applications need permission to implement/support this feature. Zip4j does not support this feature at the moment.