can we make that happen?
It's certainly possible to add encryption support to ZipArchives. There are a few competing standards for which encryption and accompanying header definitions, but I think the AES one used by 7-zip is one of the more popular ones. There's also basic passwords included in the zip format but iirc those are easily crackable.
The format also has some strong encryption support but it's copyrighted so out of bounds for us.
We need API proposal to move it further.
Speaks something against?
namespace System.IO.Compression
{
public static class ZipFile
{
public static ZipArchive Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding, string password)
}
}
@ianhays can you please comment if that is sufficient?
@lburkovsky take a look at this issue for a good example of the kind of API proposal that we're looking for. In general, the more implementation details, the better. You can also look at our API Review process doc for more info on the process.
For Zip password support specifically, an API proposal should include analysis on the different methods of password support in Zip, the pros and cons of each, and which you think should be officially supported in .NET.
@neridonk perhaps you would like to make the proposal for us to formally review? as above.
Any news or plans about this feature? Would be very useful!
@mfjerome we are open to API proposal and contribution. Are you interested?
What do we need this feature for? Is it for reading password-protected files or producing or something else?
@bartonjs can you please chime in?
I'm not quite sure what's being asked of me here. So here are words.
All further comments relate to the WinZIp version:
The preference in cryptography API is to never have a default algorithm choice, so creating new encrypted ZIP files would require using a method that took that as an input. That might mean that instead of
```C#
public static ZipArchive Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding, string password);
You want
```C#
public enum ZipEncryptionMode
{
Unknown,
Aes128,
Aes192,
Aes256,
}
public static ZipArchive OpenRead(string archiveFileName, Encoding entryNameEncoding, string password);
public static ZipArchive OpenCreate(string archiveFileName, Encoding entryNameEncoding, string password, ZipEncryptionMode encryptionMode);
public static ZipArchive OpenUpdate(string archiveFileName, Encoding entryNameEncoding, string password, ZipEncryptionMode encryptionMode);
Or, you could combine them:
```C#
public enum ZipEncryptionMode
{
Unknown,
Aes128,
Aes192,
Aes256,
}
// Update/Create modes will throw if newFileEncryptionMode is default
public static ZipArchive Open(string archiveFileName, Encoding entryNameEncoding, string password, ZipEncryptionMode newFileEncryptionMode = default);
```
This is all unfortunate that you're holding the password string in memory. Being able to take it as a ReadOnlySpan
So, short form:
I think this issue can resolve my feature needed in https://developercommunity.visualstudio.com/idea/368318/add-password-protected-zip-file-to-systemiocompres.html
Most helpful comment
I'm not quite sure what's being asked of me here. So here are words.
All further comments relate to the WinZIp version:
The preference in cryptography API is to never have a default algorithm choice, so creating new encrypted ZIP files would require using a method that took that as an input. That might mean that instead of
```C#
public static ZipArchive Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding, string password);
Or, you could combine them:
```C#
public enum ZipEncryptionMode
{
Unknown,
Aes128,
Aes192,
Aes256,
}
// Update/Create modes will throw if newFileEncryptionMode is default
public static ZipArchive Open(string archiveFileName, Encoding entryNameEncoding, string password, ZipEncryptionMode newFileEncryptionMode = default);
```
This is all unfortunate that you're holding the password string in memory. Being able to take it as a ReadOnlySpan would be nicer, but requires moving the encrypt/decrypt to verbs on ZipFileEntry (which may be useful anyways, for degenerate files that use multiple different passwords).
So, short form: