Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

November 22, 2006

How to Determine if a Zip is Encrypted or Password-Protected?

I received a great question today: How do you determine if a .zip file is password-protected or AES strong encrypted? Here is the answer, in C# code. The equivalent code can be used in VB.NET, ASP, VB6, C++, Ruby, Perl, Python, Java, etc. using the Chilkat Zip component because the API (method and properties) are identical across platforms…

// This example discusses how to determine if a Zip is
// password-protected or WinZip AES encrypted.
Chilkat.Zip zip = new Chilkat.Zip();
zip.UnlockComponent("Anything for 30-day trial");
	
string zipFilename = "myZip.zip";
	
// Password-protected Zips cannot be opened without
// first providing the password.
// Therefore, there is a method available to test a .zip
// for this condition:
bool isPwdProtected = zip.IsPasswordProtected(zipFilename);
if (isPwdProtected)
{
    MessageBox.Show("This zip is password-protected and requires a password to open.");
    return;
}
	
// WinZip AES encrypted zips can technically be opened
// without first providing a password.  That is because
// the encryption occurs on a per-entry basis within the
// zip.  It is possible that some files within the zip
// may be encrypted, and others not.  It is also possible
// that some files within the zip may be encrypted differently
// or with different passwords.  It is generally not possible
// to mix older Zip 2.0 encryption (password-protected) with WinZip
// AES encryption.
bool success = zip.OpenZip(zipFilename);
if (!success)
{
    MessageBox.Show(zip.LastErrorText);
    return;
}
	
// If an entry's compression method = 99, it is AES encrypted.
// Your application may decide to check only the 1st entry within
// the zip, or all of them:
	
// To check the 1st entry:
Chilkat.ZipEntry entry = zip.GetEntryByIndex(0);
if (entry.CompressionMethod == 99)
{
    MessageBox.Show("This zip is WinZip AES strong encrypted!");
    return;
}
	
// To check all the entries within the zip:
int i;
int n = zip.NumEntries;
for (i=0; i<n; i++)
{
    entry = zip.GetEntryByIndex(i);
    if (entry.CompressionMethod == 99)
    {
	MessageBox.Show("This zip is WinZip AES strong encrypted!");
	return;
    }
}
	
MessageBox.Show("We got here, so the Zip is not encrypted!");	    
	


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.