Using SharpZipLib, the following code works. And by works I mean entry.IsCrypted
returns true or false based on whether or not there is a password for the first entry in the zip file.
var file = @"c:\testfile.zip";
FileStream fileStreamIn = new FileStream(file, FileMode.Open, FileAccess.Read);
ZipInputStream zipInStream = new ZipInputStream(fileStreamIn);
ZipEntry entry = zipInStream.GetNextEntry();
Console.WriteLine("IsCrypted: " + entry.IsCrypted);
There's a simple tutorial on using SharpZipLib on CodeProject.
Thus a simple implementation looks something like:
public static bool IsPasswordProtectedZipFile(string path)
{
using (FileStream fileStreamIn = new FileStream(path, FileMode.Open, FileAccess.Read))
using (ZipInputStream zipInStream = new ZipInputStream(fileStreamIn))
{
ZipEntry entry = zipInStream.GetNextEntry();
return entry.IsCrypted;
}
}
Note there's no real error handling or anything...