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

setPassword corrupting files #30

Open
bradley-varol opened this issue Nov 16, 2018 · 6 comments
Open

setPassword corrupting files #30

bradley-varol opened this issue Nov 16, 2018 · 6 comments

Comments

@bradley-varol
Copy link

bradley-varol commented Nov 16, 2018

Description
setPassword corrupts my CSV files

How to reproduce

$zipFile = new ZipFile;

$zipFile->addDir($dir); // directory with several very small .csv files

$zipFile->setPassword('password');

$zipFile->saveAsFile('path.zip')->close();
@Ne-Lexa
Copy link
Owner

Ne-Lexa commented Nov 16, 2018

Attach the created zip-archive and report the version of the library, PHP, OS.

@bradley-varol
Copy link
Author

bradley-varol commented Nov 16, 2018

I won't be able to attach the created zip. It was the most recent version, PHP7.1 and Windows 10.
I also had issues getting PHP's ZipArchive to work on W10.

@529834149
Copy link

Have you solved this problem? My version is version php5.6. After setting the password, it will prompt that the file is damaged when decompressing

@bradley-varol
Copy link
Author

Sorry @529834149 but I no longer work on the project that I encountered this on, and I don't remember the solution. I think I used a different package!

@mbardelmeijer
Copy link
Contributor

We're having the same issue here. Anyone know a workaround for this?

@odan
Copy link
Contributor

odan commented Aug 22, 2021

I have tried to reproduce this issue on Windows 10.

When I extract the file with 7-ZIP the password-protected ZIP file can be extracted.
But when I use the Windows 10 built-in function to extract ZIP archives from the (right-click) context, an unexpected error occurs.

This error usually occurs when a ZIP file is encrypted with a password, but Windows cannot detect that it is an encrypted file.

Error 0x80004005: Unspecified error

Then I tried to encrypt the ZIP files with different encryption methods and decrypt it with the Windows built-in function.

Here are the results:

This file was created with 7-ZIP

It seems that Windows (10) supports only the traditional PKWARE encryption and ZipCrypto, but not AES-*.

Read more

So, to make it work on Windows, just pass ZipEncryptionMethod::PKWARE as the second parameter.

Working example:

use PhpZip\Constants\ZipEncryptionMethod;
use PhpZip\ZipFile;
// ...

$zipFile = new ZipFile();
$zipFile->addDir(__DIR__ . '/csv');
$zipFile->setPassword('password', ZipEncryptionMethod::PKWARE);

$zipFile->saveAsFile(__DIR__ . '/zipfile-pkware.zip')->close();

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

5 participants