1

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

2 Answers 2

1

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).

3
  • 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
    Apr 15, 2010 at 14:09
  • 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
    Apr 15, 2010 at 15:52
  • Yes, in the end using the command-line ZIP tool worked. Thanks.
    – gordon
    Apr 16, 2010 at 23:04
0

Have a look at 7z project, it worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.