
ZIP files remain the most popular format for compressing and sharing data. C# developers can quickly generate encrypted or password‑protected ZIP archives using Aspose.ZIP for .NET. This guide provides a comprehensive, SEO‑focused walkthrough on creating secure ZIP files, applying AES encryption, protecting folders, and mixing encryption methods—all with clear C# code examples.
The following topics are covered:
- C# API to Create Encrypted ZIP Files
- Create Password-Protected ZIP Files
- Create Encrypted ZIP Files with AES Encryption
- Encrypt Folders in ZIP Files
- Encrypt Specific Files in ZIP Archives
- Create Encrypted ZIP Files with Mixed Encryption
C# API to Create Encrypted ZIP Files
To create encrypted ZIP archives, use the Aspose.ZIP for .NET API. It compresses files and folders, adds them to ZIP archives, and can decompress formats like ZIP, TAR, GZIP, BZ2, 7Zip, RAR, etc. The API supports password protection and AES encryption (AES‑128, AES‑192, AES‑256).
You can either download the DLL or install it via NuGet.
Install-Package Aspose.ZIP
Create Password-Protected ZIP Files
Follow these steps to create a password‑protected ZIP archive:
- Create an Archive instance with an ArchiveEntrySettings object.
- Set the password using the TraditionalEncryptionSettings object.
- Call CreateEntry() with the input file path to add a file.
- Repeat step 3 for additional files.
- Call _Save() with the output path to write the archive.
The code sample below demonstrates how to create a password‑protected ZIP file using C#.

Create Password-Protected ZIP Archives
The Archive class represents a ZIP file and provides methods to create, extract, or update archives. CreatEntry() adds a single file; overloads also allow adding from a stream or FileInfo. Save() writes the archive to disk.
ArchiveEntrySettings defines compression options. TraditionalEncryptionSettings configures the legacy ZipCrypto algorithm. Its Password property sets the password for encryption or decryption.
Create Encrypted ZIP Files with AES Encryption
Use these steps to encrypt a ZIP archive with AES:
- Create an Archive instance with an ArchiveEntrySettings object.
- Set the password using AesEncryptionSettings, passing the password string and an _EncryptionMethod_.
- Call CreateEntry() with the input file path.
- Repeat step 3 for additional files.
- Call _Save() with the output path.
The sample below shows how to create an AES‑encrypted ZIP file using C#.
AesEncryptionSettings configures the AES algorithm, a symmetric block cipher. Available encryption methods are:
- Traditional — legacy PKWARE encryption
- AES128 — 128‑bit key
- AES192 — 192‑bit key
- AES256 — 256‑bit key
Encrypt Folders in ZIP Files
Add password‑protected folders with these steps:
- Create an Archive instance with an ArchiveEntrySettings object.
- Set the password using TraditionalEncryptionSettings.
- Call CreateEntries() with the folder path.
- Repeat step 3 for additional folders.
- Call _Save() with the output path.
The code sample below demonstrates how to add an encrypted folder to a ZIP file using C#.
Encrypt Specific Files in ZIP Archives
Encrypt individual files with these steps:
- Create an Archive instance.
- Call CreateEntry() with the first file path.
- Set a password for that entry using ArchiveEntrySettings with TraditionalEncryptionSettings.
- Call CreateEntry() for the next file.
- Repeat as needed.
- Call _Save() with the output path.
The sample below shows how to encrypt specific files in a ZIP archive using C#.

Encrypt Specific Files in ZIP archives
Create Encrypted ZIP Files with Mixed Encryption
Create archives that mix encryption types using these steps:
- Create an Archive instance.
- Call CreateEntry() with the first file path.
- Set its password using ArchiveEntrySettings with AesEncryptionSettings.
- Call CreateEntry() for a second file.
- Set its password using ArchiveEntrySettings with TraditionalEncryptionSettings.
- Call CreateEntry() for a third file.
- Call CreateEntries() with a folder path.
- Save the archive using _Save() with the output path.
The code sample below illustrates how to create a ZIP file with mixed encryption techniques using C#.

Create Encrypted ZIP File with Mixed Encryption
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
Conclusion
This article showed how to create encrypted ZIP files using C#. You also learned to create password‑protected ZIP files, encrypt specific files, add protected folders, and build ZIP archives with mixed encryption. Explore more about Aspose.ZIP for .NET in the documentation. For questions, visit the forum.