[PR #1059] Add ZIP password encryption support for writing archives #1487

Open
opened 2026-01-29 22:20:48 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/1059
Author: @Copilot
Created: 12/2/2025
Status: 🔄 Open

Base: masterHead: copilot/add-password-support-zip-files


📝 Commits (8)

  • 94b4100 Initial plan
  • 6efb8be Add ZIP password encryption support with WinZip AES-128/AES-256
  • 42bbfa0 Add documentation for NonDisposingStream class
  • 0d6b0aa Merge from master and resolve conflicts - update ZStandard API and ArchiveEncoding interface
  • 68279e0 Merge branch 'master' into copilot/add-password-support-zip-files
  • 4910d6b Fix .NET Standard 2.0 build error - use compatible Rfc2898DeriveBytes constructor
  • c64cc98 back to simpler include
  • 0b6831b minor update

📊 Changes

8 files changed (+798 additions, -29 deletions)

View changed files

📝 src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs (+39 -0)
src/SharpCompress/Common/Zip/WinzipAesEncryptionStream.cs (+205 -0)
src/SharpCompress/Common/Zip/ZipEncryptionType.cs (+30 -0)
📝 src/SharpCompress/Common/Zip/ZipHeaderFactory.cs (+2 -2)
📝 src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs (+61 -3)
📝 src/SharpCompress/Writers/Zip/ZipWriter.cs (+234 -24)
📝 src/SharpCompress/Writers/Zip/ZipWriterOptions.cs (+18 -0)
📝 tests/SharpCompress.Test/Zip/ZipWriterTests.cs (+209 -0)

📄 Description

  • Understand the issue: Add password support for writing ZIP files
  • Explore existing codebase for encryption support (PkwareTraditionalEncryptionData, WinzipAesEncryptionData)
  • Identify that reading encrypted ZIPs is supported, but writing is not
  • Understand existing ZipWriter structure and how encryption flags work
  • Add Password property to ZipWriterOptions
  • Add EncryptionType property to ZipWriterOptions (for choosing Pkware vs AES encryption)
  • Create ZipEncryptionType enum with None, PkwareTraditional, Aes128, Aes256 options
  • Create WinzipAesEncryptionStream for writing WinZip AES encrypted data
  • Add ForWrite factory method to PkwareTraditionalEncryptionData
  • Modify ZipWriter to support password-based encryption during writing
  • Fix flag preservation bug when updating local header in seekable streams
  • Update ZipCentralDirectoryEntry to include encryption info in central directory
  • Add tests for password-protected ZIP writing (AES-128, AES-256, multiple files)
  • Verify the encrypted ZIPs can be read back successfully
  • Run code review and address feedback
  • Merge from master and resolve conflicts:
    • Updated ZStandard CompressionStream API (removed ZstdSharp prefix, use CompressionStream with output stream for encryption support)
    • Updated PkwareTraditionalEncryptionData.ForWrite to accept IArchiveEncoding interface
    • Added using statement for SharpCompress.Compressors.ZStandard
  • Fix .NET Standard 2.0 build error:
    • Updated WinzipAesEncryptionStream to use compatible Rfc2898DeriveBytes constructor
    • .NET Standard 2.0 doesn't support HashAlgorithmName parameter, use 3-parameter constructor
  • All tests passing (57 encryption tests, 17 ZIP writer tests)
  • Build successful for all target frameworks (net48, netstandard2.0, net8.0, net10.0)
Original prompt

This section details on the original issue you should resolve

<issue_title>Support for Setting Password on ZIP Files</issue_title>
<issue_description>Hello,

I am currently using the SharpCompress library for compressing files into ZIP archives. However, I need to set a password on the ZIP files and it appears that there is no support for this feature directly.

Is there any way to set a password for ZIP files using SharpCompress? If not, are there any plans to add this feature in the future?</issue_description>

Comments on the Issue (you are @copilot in this section)


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/1059 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 12/2/2025 **Status:** 🔄 Open **Base:** `master` ← **Head:** `copilot/add-password-support-zip-files` --- ### 📝 Commits (8) - [`94b4100`](https://github.com/adamhathcock/sharpcompress/commit/94b4100a88169423892b22ac38c5a385c1cb8391) Initial plan - [`6efb8be`](https://github.com/adamhathcock/sharpcompress/commit/6efb8be03a91740c3eb21ec56adf07e40d28fd6f) Add ZIP password encryption support with WinZip AES-128/AES-256 - [`42bbfa0`](https://github.com/adamhathcock/sharpcompress/commit/42bbfa08a9bd75d3d8e2623a41e00b721ef7af98) Add documentation for NonDisposingStream class - [`0d6b0aa`](https://github.com/adamhathcock/sharpcompress/commit/0d6b0aa1ab241863990fde5238575f757318d59c) Merge from master and resolve conflicts - update ZStandard API and ArchiveEncoding interface - [`68279e0`](https://github.com/adamhathcock/sharpcompress/commit/68279e0a2be16c798b77be4725ec2da81d114174) Merge branch 'master' into copilot/add-password-support-zip-files - [`4910d6b`](https://github.com/adamhathcock/sharpcompress/commit/4910d6b567007d04e843eb22e77d52c5eedd86d9) Fix .NET Standard 2.0 build error - use compatible Rfc2898DeriveBytes constructor - [`c64cc98`](https://github.com/adamhathcock/sharpcompress/commit/c64cc98ca73659d30784687a01c0715128d944aa) back to simpler include - [`0b6831b`](https://github.com/adamhathcock/sharpcompress/commit/0b6831b3f2487adf1fb9ee9a0eca1b3d447e473d) minor update ### 📊 Changes **8 files changed** (+798 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs` (+39 -0) ➕ `src/SharpCompress/Common/Zip/WinzipAesEncryptionStream.cs` (+205 -0) ➕ `src/SharpCompress/Common/Zip/ZipEncryptionType.cs` (+30 -0) 📝 `src/SharpCompress/Common/Zip/ZipHeaderFactory.cs` (+2 -2) 📝 `src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs` (+61 -3) 📝 `src/SharpCompress/Writers/Zip/ZipWriter.cs` (+234 -24) 📝 `src/SharpCompress/Writers/Zip/ZipWriterOptions.cs` (+18 -0) 📝 `tests/SharpCompress.Test/Zip/ZipWriterTests.cs` (+209 -0) </details> ### 📄 Description - [x] Understand the issue: Add password support for writing ZIP files - [x] Explore existing codebase for encryption support (PkwareTraditionalEncryptionData, WinzipAesEncryptionData) - [x] Identify that reading encrypted ZIPs is supported, but writing is not - [x] Understand existing ZipWriter structure and how encryption flags work - [x] Add Password property to ZipWriterOptions - [x] Add EncryptionType property to ZipWriterOptions (for choosing Pkware vs AES encryption) - [x] Create ZipEncryptionType enum with None, PkwareTraditional, Aes128, Aes256 options - [x] Create WinzipAesEncryptionStream for writing WinZip AES encrypted data - [x] Add ForWrite factory method to PkwareTraditionalEncryptionData - [x] Modify ZipWriter to support password-based encryption during writing - [x] Fix flag preservation bug when updating local header in seekable streams - [x] Update ZipCentralDirectoryEntry to include encryption info in central directory - [x] Add tests for password-protected ZIP writing (AES-128, AES-256, multiple files) - [x] Verify the encrypted ZIPs can be read back successfully - [x] Run code review and address feedback - [x] Merge from master and resolve conflicts: - Updated ZStandard CompressionStream API (removed ZstdSharp prefix, use CompressionStream with output stream for encryption support) - Updated PkwareTraditionalEncryptionData.ForWrite to accept IArchiveEncoding interface - Added using statement for SharpCompress.Compressors.ZStandard - [x] Fix .NET Standard 2.0 build error: - Updated WinzipAesEncryptionStream to use compatible Rfc2898DeriveBytes constructor - .NET Standard 2.0 doesn't support HashAlgorithmName parameter, use 3-parameter constructor - [x] All tests passing (57 encryption tests, 17 ZIP writer tests) - [x] Build successful for all target frameworks (net48, netstandard2.0, net8.0, net10.0) <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Support for Setting Password on ZIP Files</issue_title> > <issue_description>Hello, > > I am currently using the `SharpCompress` library for compressing files into ZIP archives. However, I need to set a password on the ZIP files and it appears that there is no support for this feature directly. > > Is there any way to set a password for ZIP files using `SharpCompress`? If not, are there any plans to add this feature in the future?</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes adamhathcock/sharpcompress#911 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/adamhathcock/sharpcompress/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:20:48 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1487