0

I been trying to creat a password protected zip file i come acorss this lirbary net.lingala.zip4j it seems that it use to protect the zip file with password.

but now i have been trying all i can do is protect the files not the zip it self, the diference is the zip can be opened and files inside can be deleted from the zip

i will show my current code but i have tryed many codes but all see to need this imports import net.lingala.zip4j.util.Zip4jConstants; import net.lingala.zip4j.core.ZipFile;

And does seem to not exist anymore in updated vertion of zip4j

any knows a way around this so i can protect the zip file it self?

try (ZipFile zipFile = new ZipFile("settings.zip", (mysqllogFile[1]).toCharArray())) {
                ZipParameters zipParameters = new ZipParameters();
                zipParameters.setEncryptFiles(true);
                zipParameters.setEncryptionMethod(EncryptionMethod.AES);
                zipParameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_256);

                zipFile.addFile("token", zipParameters);
                zipFile.addFile("mysqllog", zipParameters);

                // delete the original files
                File tokenFile = new File("token");
                tokenFile.delete();
                File mysqlLogFile = new File("mysqllog");
                mysqlLogFile.delete();


                System.out.println("Files zipped successfully!");
            } catch (ZipException e) {
                e.printStackTrace();
            }
  • Are you trying to migrate from zip4j 1.x version to zip4j 2.x? Zip4jConstants is removed in 2.x which used to exist in 1.x. You won't need this in 2.x. And net.lingala.zip4j.core.ZipFile has moved to net.lingala.zip4j.ZipFile in 2.x. – Srikanth Reddy Lingala Mar 10 '23 at 16:16
  • i don't want to migrate i just want to protect the zip file with a password, wich was possible in 1x and now i can only protect files inside not the zip it self – Ivan Lopes Mar 15 '23 at 06:10
  • Even in 1.x it was just the files which were encrypted. Zip4j did not encrypt the complete zip file, doing which will break zip specification. The functionality remains the same in 2.x as in 1.x. In fact, I urge you to upgrade to 2.x as there are several bug fixes in the latest version compared to 1.x, which is not maintained anymore. – Srikanth Reddy Lingala Mar 24 '23 at 13:41

0 Answers0