Access Protected ZIP

ZIP archives offer a convenient way to compress multiple files for easy sharing over digital platforms. However, there are instances when a ZIP file containing sensitive information is accidentally sent to unintended recipients. Therefore, the capability to encrypt and decrypt files in compliance with industry standards is essential in any ZIP library.

IronZIP stands out by enabling users to decrypt protected ZIP files with just a few lines of code, and it also allows the encryption of existing ZIP archives using passwords and various encryption methods. This versatility makes it suitable for a wide range of situations.

Access Protected ZIP with C#

  1. using IronZip
  2. using IronZip.Enum;
  3. using (var archive = new IronZipArchive("existing.zip", "P@ssw0rd"))
  4. archive.Encrypt("P@ssw0rd", EncryptionMethods.AES256);

Accessing Protected ZIP Archive

We first import the namespace IronZip. Afterward, we initialize a new IronZipArchive, and then we input two parameters, the first one being the path to the protected ZIP you're trying to access and the second being the password to access the protected ZIP. Do note that if the password or the path is incorrect, the operation will fail. Once the correct password is provided, the ZIP file can be decrypted, and its contents can be viewed, extracted, or modified.

Encrypting the Existing ZIP Archive

Aside from accessing the protected ZIP with the IronZipArchive class, IronZIP also allows you to encrypt the archive with a chosen encryption. To do this, we first import the IronZip.Enum , importing the enums will enable developers to select the encryption method used to encrypt the archive. Finally, we call the Encrypt method with two parameters passed in. The first one is the password that you wish to use to encrypt the ZIP Archive, while the second one is the EncrpytionMethods enum. Within this example, we will be using EncryptionMethods.AES256 to encrypt the file. After encrypting the file, you can confirm the operation by providing the password to access the protected ZIP again to verify. For a complete list of supported encryption methods and their related enums, please refer here.

Discover how to create, read, and extract ZIP files effortlessly with our complete tutorial.

Talk to an Expert Five Star Trust Score Rating

Ready to Get Started?

Nuget Passed