Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: CRC Failed in encrypted file. Wrong password - while unzip using 7-zip #534

Open
sreenivasulun2007 opened this issue Jan 22, 2024 · 2 comments

Comments

@sreenivasulun2007
Copy link

sreenivasulun2007 commented Jan 22, 2024

Hello Srikanth,
Hopefully all is well with you. Thanks your wonderful library.
We are using zip4j-1.3.2 library to create password encrypted zip file.
And then, when we try to unzip the file with the tool 7-zip, we are getting the following error and the issue is intermittent,
ERROR: CRC Failed in encrypted file. Wrong password

As follows the code util to create the zip file,


import java.io.File;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ZipFileUtil {
	private static final Logger logger = LoggerFactory.getLogger(ZipFileUtil.class);
	public static final String ZIP_WITH_DOT                  = ".zip";
	public static final String DOT                  = ".";
	/**
	 * Method for creating password protected zip file
	 * 
	 * @param sourcePath
	 * @throws ZipException
	 */
	public String compressWithPassword(String sourcePath, String zipFilePassword) throws ZipException {
		try {
			//String destPath = sourcePath + ".zip";
			String zipFileName=sourcePath.substring(0,sourcePath.lastIndexOf(DOT))+ ZIP_WITH_DOT;
			logger.info("ZIP File Name " + zipFileName);
			ZipFile zipFile = new ZipFile(zipFileName);
			// Setting parameters
			ZipParameters zipParameters = new ZipParameters();
			zipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
			zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA);
			zipParameters.setEncryptFiles(true);
			zipParameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
			zipParameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
			// Setting password
			zipParameters.setPassword(zipFilePassword);
			zipFile.addFile(new File(sourcePath), zipParameters);
			return zipFileName;
		} catch (ZipException e) {
			logger.error("exception while zip for file:" + sourcePath + " error:" + e.getMessage());
			throw new ZipException(e);
		}
		
	}
}

Please advice the best solution for this issue. . In order to fix it, we suggested to upgrade to the version2.11.5 to my boss but he is asking the root cause. My boss is telling that we cannot just upgrade the library in production without proper root cause to explain to management.
Thank you,
Sreenivasulu N

@sreenivasulun2007 sreenivasulun2007 changed the title ERROR: CRC Failed in encrypted file. Wrong password - while unzip using WinRAR 6.24 ERROR: CRC Failed in encrypted file. Wrong password - while unzip using 7-zip Jan 22, 2024
@sreenivasulun2007
Copy link
Author

Hello Srikanth,
We decided to upgrade zip4j from v1.3.2 to v2.11.5 since it takes less effort.
Thank you again for your wonderful library.

@sreenivasulun2007
Copy link
Author

I will wait for few more days if you have any feedback. Otherwise, I will close the ticket after few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant