How to protect the zip files using Syncfusion.Compression.Base?

8 Dec 20232 minutes to read

Password is used for protecting files which needs more security. This can be achieved by using various encryption algorithms. The compressed zip files can be protected using encryption algorithms with password as a key for that algorithm.

Syncfusion.Compression.Base supports AES-128 bits, AES-192 bits, AES-256 bits and ZipCrypto encryption algorithms. These encryption algorithms are available under the enumeration EncryptionAlgorithm.

The following complete code snippet explains how to protect a zip file with password using AES-256 bits encryption algorithm.

using Syncfusion.Compression.Zip;

class Program
{
  static void Main(string[] args)
  {
    //Initialize ZipArchive
    ZipArchive zipArchive = new ZipArchive();

    //Add files into ZipArchive
    zipArchive.AddFile("../../Data/Template1.txt");
    zipArchive.AddFile("../../Data/Template2.txt");
    zipArchive.AddFile("../../Data/Template3.txt");

    //Protect the ZipArchive with password
    zipArchive.Protect("password", EncryptionAlgorithm.AES256);

    //Save the ZipArchive
    zipArchive.Save("WithPassword256Bit.zip");
  }
}
Imports Syncfusion.Compression.Zip

Module Module1
  Sub Main()
    'Initialize ZipArchive
    Dim zipArchive As ZipArchive = New ZipArchive

    'Add files into ZipArchive
    zipArchive.AddFile("../../Data/Template1.txt")
    zipArchive.AddFile("../../Data/Template2.txt")
    zipArchive.AddFile("../../Data/Template3.txt")

    'Protect the ZipArchive with password
    zipArchive.Protect("password", EncryptionAlgorithm.AES256)

    'Save the ZipArchive
    zipArchive.Save("WithPassword256Bit.zip")
  End Sub
End Module

See Also