Search code examples
.netencryptionphp-ziparchive

Encryption/Decryption using ZipArchive class


I did some investigation and cannot see native way to implement encryption/decryption using ZipArchive class.

https://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive(v=vs.110).aspx

It seems like MSDN does not provide this posibility...

Am I right and if I am not then how to encrypt/decrypt ZIP using ZipArchive class?

Thanks!

P.S. Is this approach a good one? Encrypt an existing zip file


Solution

  • You can stop looking, Microsoft did not implement it. Encrypting the file(s) yourself before adding them to the archive is an obvious workaround but doesn't exactly give the recipient a shot at decrypting them again.

    You'll have to fall back to the kind of libraries that were popular before .NET got zip file support. Lots to choose from, SharpZipLib and DotNetZip where the leading contenders. Both support a password on the archive and allow you to control the encryption algorithm when you create the archive, important if you care about the weak Zip 2.0 algorithm.