Skip to content

Add password-protected archives and CLI tools#394

Merged
kuba-- merged 1 commit intomasterfrom
feature/password-support
Mar 15, 2026
Merged

Add password-protected archives and CLI tools#394
kuba-- merged 1 commit intomasterfrom
feature/password-support

Conversation

@kuba--
Copy link
Copy Markdown
Owner

@kuba-- kuba-- commented Mar 15, 2026

Implement Traditional PKWARE Encryption (APPNOTE 6.1) for reading and writing password-protected zip archives. The feature is fully backward compatible -- existing APIs and non-password usage are unchanged.

New public API:

  • zip_open_with_password / zip_open_with_password_and_error
  • zip_stream_open_with_password
  • ZIP_EPASSWD error code

Encryption details:

  • PKWARE cipher key derivation with raw (uncomplemented) CRC32
  • On-the-fly encryption via tdefl callback for compressed entries
  • Re-encryption at entry close to patch the CRC-based check byte, ensuring interoperability with Info-ZIP unzip and Python zipfile
  • Supports both compressed (deflate) and stored (level 0) entries

Add standalone CLI tools (gated behind -DZIP_BUILD_TOOLS=ON):

  • zipcli -- create archives, with optional -p password
  • unzipcli -- list/extract archives, with optional -p password

Add comprehensive test suite (test/test_password.c, 17 tests) covering write/read round-trips, wrong passwords, stream API, entry deletion, large data, and multiple writes per entry.

Update README.md with password-protected archive examples.

Closes https://github.com/kuba--/zip/issues/358

Implement Traditional PKWARE Encryption (APPNOTE 6.1) for reading and
writing password-protected zip archives.  The feature is fully backward
compatible -- existing APIs and non-password usage are unchanged.

New public API:
  - zip_open_with_password / zip_open_with_password_and_error
  - zip_stream_open_with_password
  - ZIP_EPASSWD error code

Encryption details:
  - PKWARE cipher key derivation with raw (uncomplemented) CRC32
  - On-the-fly encryption via tdefl callback for compressed entries
  - Re-encryption at entry close to patch the CRC-based check byte,
    ensuring interoperability with Info-ZIP unzip and Python zipfile
  - Supports both compressed (deflate) and stored (level 0) entries

Add standalone CLI tools (gated behind -DZIP_BUILD_TOOLS=ON):
  - zipcli  -- create archives, with optional -p password
  - unzipcli -- list/extract archives, with optional -p password

Add comprehensive test suite (test/test_password.c, 17 tests) covering
write/read round-trips, wrong passwords, stream API, entry deletion,
large data, and multiple writes per entry.

Update README.md with password-protected archive examples.
@kuba-- kuba-- force-pushed the feature/password-support branch from 50b259d to 4069e17 Compare March 15, 2026 14:28
@kuba-- kuba-- merged commit f5c95f0 into master Mar 15, 2026
16 checks passed
@kuba-- kuba-- deleted the feature/password-support branch March 15, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant