Zip 2.0 Encryption

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikesmith76
Forum Commoner
Posts: 34
Joined: Fri Aug 25, 2006 7:10 am
Location: Manchester, UK

Zip 2.0 Encryption

Post by mikesmith76 »

Hi all,

I need to send a file in "standard 2.0 encryption" (not my words). I have no control over this format as it is going to an external company, and this is the format the file must be sent in. Inside the encrypted zip file will be a csv file, possibly growing to several thousand lines a time. I have seen the excellent zip file classes around the forum (and on other places) but none that I have seen support zip encryption. To tell you the truth I'm not even sure what they been by "standard 2.0 encryption".

Has anybody else faced a similar need to send encrypted zip files, and found a suitable solution.

Thanks for all your help
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

You don't mention which system you are working on (Linux/Windows).

I would use exec a system command to zip the file before sending. Just google for "zip standard 2.0 encryption" for applications handling it on your platform. Doing this means if you ever need zip standard 3.0 encryption (doesn't exist yet as far as I know), your system just needs to be updated with the relevant application. If both you and your client use the same application you can guarantee you both can unzip each others zip files.

The alternative is to use the PECL Zip utility but I am not sure which encrytion it uses. I would imagine it would be correct but you may want to send a test file first.
mikesmith76
Forum Commoner
Posts: 34
Joined: Fri Aug 25, 2006 7:10 am
Location: Manchester, UK

Post by mikesmith76 »

Sorry the app is hosted on a dedicated linux server that I have command line access to. Just searching now on what command line tools are available for use. From what i've read on the security aspect of the format it's not much better than having no password set, but we do what were told...
mikesmith76
Forum Commoner
Posts: 34
Joined: Fri Aug 25, 2006 7:10 am
Location: Manchester, UK

Post by mikesmith76 »

Sorry to be a moron but i have a problem with the Linux "zip" command

If i run the following command (both on the command line and in php) all is well

zip /test/test.zip /test/test.csv

However to encrypt the contents i need to use the -e flag as in

zip -e /test/test.zip /test/test.csv

Doing this on the command line results in a prompt for a password. I have tried to replicate this functionality in using both proc_open and popen, no luck with either. With proc_open all i get returned is "Command Returned 16". popen is one way to no feedback there, and no zip file either. The code I used for both of the above commands was taken from the php manual examples (as i have never used either of these commands before).

This is to be hosted on a Linux server, running php 4.2 I think. I don't want to upgrade the version of php as a number of other apps are running on this server, and i don't want to check each and every one for bugs after the upgrade.

I'm probably doing something really stupid, if anyone want's to point me in the right direction I would appreciate it
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's a zip class in Code Snippets too. ;)
mikesmith76
Forum Commoner
Posts: 34
Joined: Fri Aug 25, 2006 7:10 am
Location: Manchester, UK

Post by mikesmith76 »

If I was just trying to zip up the file that would be great. Reading through the class you mentionned it doesn't appear to support password protection of any kind, and I'm a bit reluctant to resurrect a 6 month old thread to speak to the class author.

After spending the afternoon playing with popen / proc_open i'm not sure I can do what I want with my current php version. Need more digging I suppose...
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Write a Bash (or whatever shell is on the server) script that acts as a wrapper. You're really going to need command line access to get it working though, or the help of someone who has access.
mikesmith76
Forum Commoner
Posts: 34
Joined: Fri Aug 25, 2006 7:10 am
Location: Manchester, UK

Post by mikesmith76 »

In the process of drawing up a quick bash script that will take the required password as a parameter. It's to be hosted on a dedicated server so I haev complete command line access. Think this problem could be a great learning experience!!
Post Reply