2

I want to create password protected ZIP:

// Set the compression level
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

// Set the encryption flag to true
// If this is set to false, then the rest of encryption properties are ignored
parameters.setEncryptFiles(true);

// Set the encryption method to Standard Zip Encryption
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);

// Set password
parameters.setPassword(password);

but this just encrypt files inside of zip but I can open this zip and watch file inside it.This is not what i want i want to make the zip password protected not the file inside it.

Victo
  • 61
  • 1
  • 5
  • Just make a zip within a zip and encrypt the inner zip :) – Ordous Dec 10 '14 at 13:29
  • On a more serious note - this is not possible. The .ZIP File Format Specification states that metadata including content list is *not* encrypted. One of the uses for that is validation of correct decryption. – Ordous Dec 10 '14 at 13:31
  • Is there any other way to make zip password protected? – Victo Dec 10 '14 at 13:35
  • You can use `winzipaes` – vzamanillo Dec 10 '14 at 15:25
  • @vzamanillo but when i tried using winzipaesi can't open the file inside the zip folder.It shows "windows cannot complete the extraction" error message. – Victo Dec 11 '14 at 07:35

1 Answers1

1

Impossible, sorry.

A file such as that would not conform to the .ZIP File Format Specification. It states that, while the actual files are encrypted, the metadata (including file names and sizes) is not encrypted. This has been a topic of debate, but this is the way it is. One of the uses of it is that you get your nice "Password was incorrect" rather than junk files.

Either way - don't rely on .zip file encryption. It's bad. No really - it's very, very bad. It's vulnerable to an entire host of attacks.

If you want a properly encrypted .zip file - do just that. Make a .zip file, and then use proper encryption to make an encrypted one. Java has quite a few encryption facilities for that.

Ordous
  • 3,844
  • 15
  • 25