SOLVED: How to check if a ZIP file is encrypted in C#.NET using Xceed ZIP.NET
If you would like to chekc whether a ZIP file is encrypted in C#.NET using Xceed ZIP.NET you can use the following code.
As a ZIP file supports the ability to encrypt each individual file (rather than the ZIP archive itself) you need to check the contents of the ZIP file and see if the files inside it are encrypted.
/// <summary>
/// Determines whether any of the contents of the specified ZIP file
is encrypted
/// </summary>
/// <param name="filename">The absolute path to the ZIP file to evaluate.</param>
/// <returns>A System.Boolean value that indicates whether any of the contents
of the specified ZIP file is encrypted.</returns>
public static bool IsEncrypted(String filename)
{
try
{
if (!File.Exists(filename)) { throw new
FileNotFoundException(Resources.CompressionSupport.FileNotFoundException); }
AbstractFile zipFile = new DiskFile(filename);
ZipArchive zip = new ZipArchive(zipFile);
AbstractFile[] files = zip.GetFiles(true);
foreach (AbstractFile file in files)
{
ZippedFile zippedFile =
(ZippedFile)file;
if (zippedFile == null) { continue; }
if (zippedFile.Encrypted) { return true; }
}
return false;
}
catch (Exception ex) { throw new
CompressionSupportException(String.Format(Resources.CompressionSupport.IsEncryptedException,
filename, ex.Message), ex);
}
}
Why not check out our Group Policy Audit and Documentation Tool?
Comments
Post a Comment