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?

Jason
  • 61
  • 1
  • 2
  • 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. – bob-the-destroyer Oct 21 '10 at 21:52
  • 1
    It seems that the AES encryption is a specific WinZIP feature, (see http://www.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? – Pelle Oct 22 '10 at 09:18
  • 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. – Jason Oct 25 '10 at 03:13
  • 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. – bob-the-destroyer Oct 29 '10 at 04:13
  • 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 :) – Prifulnath Jan 30 '17 at 08:29

2 Answers2

2

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
MoreIT
  • 73
  • 3
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

bob-the-destroyer
  • 3,164
  • 2
  • 23
  • 30