Extract Protected ZIP

Extracting Protected ZIP Archives with IronZIP

IronZIP allows you to extract protected ZIP archives that use normal, AES128, and AES256-based encryption.

To extract a protected ZIP archive, you will need to specify the correct password for the archive. This is done by providing the password as the value for the Password parameter in the ExtractArchiveToDirectory method. Additionally, you need to specify the location of the ZIP file and the directory where you want the extracted files to be saved.

Below is an example that demonstrates how to use IronZIP to extract a protected ZIP file using C#:

using IronZIP; // Include the IronZIP namespace

class Program
{
    static void Main()
    {
        // Specify the location of the ZIP file
        string zipFilePath = @"C:\path\to\your\archive.zip";

        // Specify the directory where the files should be extracted
        string extractDirectory = @"C:\path\to\extract\directory";

        // Specify the password for the ZIP file
        string zipPassword = "yourPassword";

        // Call the ExtractArchiveToDirectory method to extract the ZIP file
        ExtractArchiveToDirectory(zipFilePath, extractDirectory, zipPassword);
    }

    /// <summary>
    /// Extracts a protected ZIP archive to a specified directory.
    /// </summary>
    /// <param name="zipFilePath">The path to the ZIP file to be extracted.</param>
    /// <param name="extractDirectory">The directory where the extracted files will be saved.</param>
    /// <param name="zipPassword">The password for the ZIP file.</param>
    static void ExtractArchiveToDirectory(string zipFilePath, string extractDirectory, string zipPassword)
    {
        // Initialize ZIP archive
        using (var zip = new IronZIP.ZipArchive(filepath: zipFilePath))
        {
            // Set the password for the ZIP archive
            zip.Password = zipPassword;

            // Extract the archive to the specified directory
            zip.ExtractToDirectory(destinationDirectory: extractDirectory);

            Console.WriteLine("Extraction complete. Files have been saved to: " + extractDirectory);
        }
    }
}
using IronZIP; // Include the IronZIP namespace

class Program
{
    static void Main()
    {
        // Specify the location of the ZIP file
        string zipFilePath = @"C:\path\to\your\archive.zip";

        // Specify the directory where the files should be extracted
        string extractDirectory = @"C:\path\to\extract\directory";

        // Specify the password for the ZIP file
        string zipPassword = "yourPassword";

        // Call the ExtractArchiveToDirectory method to extract the ZIP file
        ExtractArchiveToDirectory(zipFilePath, extractDirectory, zipPassword);
    }

    /// <summary>
    /// Extracts a protected ZIP archive to a specified directory.
    /// </summary>
    /// <param name="zipFilePath">The path to the ZIP file to be extracted.</param>
    /// <param name="extractDirectory">The directory where the extracted files will be saved.</param>
    /// <param name="zipPassword">The password for the ZIP file.</param>
    static void ExtractArchiveToDirectory(string zipFilePath, string extractDirectory, string zipPassword)
    {
        // Initialize ZIP archive
        using (var zip = new IronZIP.ZipArchive(filepath: zipFilePath))
        {
            // Set the password for the ZIP archive
            zip.Password = zipPassword;

            // Extract the archive to the specified directory
            zip.ExtractToDirectory(destinationDirectory: extractDirectory);

            Console.WriteLine("Extraction complete. Files have been saved to: " + extractDirectory);
        }
    }
}
Imports IronZIP ' Include the IronZIP namespace

Friend Class Program
	Shared Sub Main()
		' Specify the location of the ZIP file
		Dim zipFilePath As String = "C:\path\to\your\archive.zip"

		' Specify the directory where the files should be extracted
		Dim extractDirectory As String = "C:\path\to\extract\directory"

		' Specify the password for the ZIP file
		Dim zipPassword As String = "yourPassword"

		' Call the ExtractArchiveToDirectory method to extract the ZIP file
		ExtractArchiveToDirectory(zipFilePath, extractDirectory, zipPassword)
	End Sub

	''' <summary>
	''' Extracts a protected ZIP archive to a specified directory.
	''' </summary>
	''' <param name="zipFilePath">The path to the ZIP file to be extracted.</param>
	''' <param name="extractDirectory">The directory where the extracted files will be saved.</param>
	''' <param name="zipPassword">The password for the ZIP file.</param>
	Private Shared Sub ExtractArchiveToDirectory(ByVal zipFilePath As String, ByVal extractDirectory As String, ByVal zipPassword As String)
		' Initialize ZIP archive
		Using zip = New IronZIP.ZipArchive(filepath:= zipFilePath)
			' Set the password for the ZIP archive
			zip.Password = zipPassword

			' Extract the archive to the specified directory
			zip.ExtractToDirectory(destinationDirectory:= extractDirectory)

			Console.WriteLine("Extraction complete. Files have been saved to: " & extractDirectory)
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

Explanation:

  • Namespaces: We start by including the IronZIP namespace, which contains the necessary classes and methods to work with ZIP archives.

  • Main Method:

    • We define file paths for the ZIP archive and the destination directory.
    • We specify the password for the ZIP archive.
    • We call the ExtractArchiveToDirectory method, passing in the necessary parameters.
  • ExtractArchiveToDirectory Method:
    • It initializes an instance of ZipArchive with the specified ZIP file path.
    • The Password property of the ZIP archive is set with the provided password.
    • The ExtractToDirectory method is called on the ZIP archive object, which extracts the files to the specified directory.
    • A confirmation message is printed to indicate the completion of the extraction process.

Note: Ensure that the file paths and password provided in the example reflect your actual setup.