How to: Password Protect Archive Files
To encrypt and password protect files in an archive, do the following:
- Create a ZipArchive class instance.
- Call its ZipArchive.AddFile method for each selected file. The method returns an object of the ZipFileItem type.
- Specify the ZipArchive.Password and ZipItem.EncryptionType properties for each item.
- 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("ProtectPassword.zip");
}
}