views:

63

answers:

1

Hi,

I have the following problem. I need to create a zip file under linux with a password provided by another party that is encoded with CP-1252. What I have tried is changing the encoding of this password to UTF-8. Then I made a zipfile protected with this utf-8 encoded password. However the file can not be unzipped in windows with the original password that is CP-1252 encoded.

Regards,

Gordon

+1  A: 

Handling a ZIP file with any content (filenames or passwords) that isn't ASCII is fraught with difficulty and best avoided. You should do everything you can to limit the allowable passwords to plain ASCII, which will work anywhere.

Each OS will treat the bytes as being in their own system default encoding, which is likely (but not certain) to be UTF-8 in recent Linuxen, UTF-8 in OS X, and never UTF-8 in Windows. Even if you create a ZIP file with a non-ASCII password encoded in cp1252, it will only be readable on Western European Windows installs. And some ZIP tools behave differently still (eg. the nautilus zip decoder seems to use ISO-8859-1 for passwords even when it is using UTF-8 for filenames). The whole thing is a broken mess.

You can create ZIP files with cp1252 passwords in Linux. What tool are you currently using to create passworded files? The command line zip tool just accepts bytes and doesn't care what encoding they're in, so to ensure any non-ASCII characters you are typing at the keyboard when it prompts you for a password are in cp1252, you should set the encoding of your terminal to cp1252. For the GNOME default ‘Terminal’ this can be done from Terminal->Set Character Encoding->Windows-1252 (you may have to Add/Remove this encoding if it is not listed).

bobince
Thanks for the explanation.I am using the ZIP tool for testing purposes. However this zip file needs to be created by a Java application that is deployed on a remote server.
gordon
Ah. You'll probably end up using the command-line ZIP for that too, as `java.util.zip` has no password capabilities (and it always uses the useless Java default charset). If you don't need the files to work on older Windowses (pre XPSP3) you might be able to use winzipaes. That library uses ISO-8859-1 for passwords, but it's easy to hack the source to change that. Unfortunately it still uses `java.util.zip`'s messed-up default-charset filenames. sigh... as I may have mentioned, non-ASCII in ZIP is a barrel of pain you should avoid at all costs.
bobince
Yes, in the end using the command-line ZIP tool worked. Thanks.
gordon