Validating a ZIP Password?

Apr 8, 2011 at 4:02 PM

I wanted to prompt the user to enter a password and check at run time if that password "works"/is the right password for a zip or self-extractor.


Is there an easy way to do this without having to try to extract something from the container?

Apr 8, 2011 at 5:28 PM

No, I don't think so.  There is no "CheckPassword" method.

The way the password works on extraction is, the validation is performed implicitly when the first bytes are read.  If that validation fails, then the call to Extract() fails with an exception.  Today, there is no way exposed by the library, to validate a  password without reading the data.

If you call ZipEntry.Extract() and specify System.IO.Stream.Null , you can extract the entry into a bitbucket.  You need not extract all bytes - just reading the first byte will validate the password. In other words, the check is about as cheap as it can be.