How to: Password Protect Archive Files

To encrypt and password protect files in an archive, do the following:

  1. Create a ZipArchive class instance.
  2. Call its ZipArchive.AddFile method for each selected file. The method returns an object of the ZipFileItem type.
  3. Specify the ZipArchive.Password and ZipItem.EncryptionType properties for each item.
  4. Call the ZipArchive.Save method to create an archive and save it to a specified location.
using DevExpress.Compression;
        public void ProtectPassword() {
            string[] sourcefiles = this.sourceFiles;
            string password = "123";
            using (ZipArchive archive = new ZipArchive()) {
                foreach (string file in sourceFiles) {
                    ZipFileItem zipFI = archive.AddFile(file, "/");
                    zipFI.EncryptionType = EncryptionType.Aes128;
                    zipFI.Password = password;
                }
                archive.Save("Documents\\ProtectPassword.zip");
            }
        }