Today I wanted to sent a password encrypted file to a Windows user and obviously the first thing that comes to mind is a password protected zip file. So I set out to create such an archive only to discover that OS X natively doesn’t support it. Not the built-in GUI unzipper (Bomarchiver I believe), nor the command-line gzip and zip. Total fail.
Now I knew for sure that zip supports encrypting files with the -e option, so the version installed on my OS X Leopard 10.5.5 wasn’t compiled with the right options.
I looked at purchasing a commercial zip utility, but I found them too expensive. C’mon, Stuffit Standard costs $49.99. A bit much if you ask me.
Anyway I decided to go for to go for the Open Source and command line based zip, except now compiled with encryption. I could have compiled from source, but I went for [Macports](http://www.macports.org “Macports”), which keeps my non-standard binaries organised under /opt.
So these are the commands I ran, to search for zip, see what variants are available and finally to install it. For more info see the [Macports website](http://www.macports.org “Macports”).
$ sudo search zip
$ sudo variants zip
$ sudo install zip
Then to figure out which zip you are using (read: is in your path first) do:
If it comes up with /usr/bin/zip you are using the standard, non-encryptorator zip. The Macports zip is installed (normally) under /opt/local/bin/zip. You can alter your path or backup the old zip and link to the new zip to solve this. Or just leave it where it is and call it directly. Whatever you fancy.
To password protect a file or files do:
$ zip -e archive.zip file1.doc file2.pdf file3.cap
And you will be prompted for a password.
Update: apperently some Mac OS X installs can encrypt zip files by default (see comments). At least as of Leopard you can do this with:
$ zip -e archive.zip <files>