How can I create a WinZip compatible AES-256 encrypted zip file from PHP on Linux?
Asked Answered
V

2

6

I have to create a WinZip compatible zip file from a PHP application on a linux box, and it must use AES 256 encryption. I have found a few solutions for PHP on Windows, but they don't help me! A PHP package would be great, but if I need to, I can always have my PHP code run exec() or something to run a linux command line utility.

Any suggestions?

Vestpocket answered 21/10, 2010 at 14:47 Comment(5)
Looks like you'll need to call an external zip program to apply encryption. PHP's built-in zip class would work fine for making/extracting generic zip files on Linux or Windows, but doesn't appear to mention any encryption support.Gigantopithecus
It seems that the AES encryption is a specific WinZIP feature, (see winzip.com/aes_info.htm) rather than a widely acknowledged standard in the world of ZIP files, making it potentially difficult to create such archives using PHP without making a call to WinZIP, especially on non-windows machines. And that makes me think: why exactly do you wish to do this? There probably are plenty of good alternatives. What OS will your script run on, and what OS will the zip files be opened on? What type of stuff do you want to protect from who, and why?Endocarp
The short answer Pelle ten Cate...my client has specified these requirements. I am hoping to get them to agree to a slight variation which is easier for me to implement.Vestpocket
zipping important documents may sometimes come hand-in-hand with encrypting them at the same time. It's a matter of convenience mixed with security. Therefore, often you'll find a simple exec command to an external zip application to both zip and apply encryption to your files at the same time is likely just fine. If encryption is not important at the time, just use PHP's zip class. If it is, call an external zip application to do that job. In other words, Woot4Moo's answer is not entirely off.Gigantopithecus
Hi Jason, have you got any solution for this? it will be great if you edit the question with your answer, if you got it :)Kinakinabalu
D
3

Not php-specific (this question is highly ranked in google also without php): 7-Zip implements this feature, in my documentation I found this command:

7za a -tzip -pPASSWORD -mem=AES256 target.zip filelist
Duckboard answered 20/8, 2015 at 15:54 Comment(1)
This question is ranked because of the given php tagHydrodynamic
G
0
  1. If a Zip application clone is not already installed on your host, just search Google for installing one of a hundred different zip applications capable of supporting both encryption and cross-platform compatibility.
  2. Use `exec` or similar PHP function to call any available external zip application capable of zipping and applying AES-256 encryption to your target file. You'll need to know any command line switches which your zip application requires to make this happen. The target file names within your `exec` string parameter can of course be switched out using variables.
  3. Serve your new zip file

However, should encryption not be a concern, see PHP's Zip class for making generic zip files: http://php.net/manual/en/book.zip.php

Gigantopithecus answered 29/10, 2010 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.