Decompressing password-protected ZIP files with .NET 4.5

前端 未结 7 790
遇见更好的自我
遇见更好的自我 2020-12-03 09:39

Microsoft introduces improvements for ZIP file handling in .NET 4.5 in the System.IO.Compression namespace. Namely the classes ZipArchive and ZipFile. However, I have not y

相关标签:
7条回答
  • 2020-12-03 10:35

    As pointed out, DotNetZip is your friend. Unpacking your zip file is as easy as

    using ( ZipFile archive = new ZipFile( @"c:\path\to\your\password\protected\archive.zip",) )
    {
      archive.Password = "your-pass-word-here" ;
      archive.Encryption = EncryptionAlgorithm.PkzipWeak ; // the default: you might need to select the proper value here
      archive.StatusMessageTextWriter = Console.Out;
    
      archive.ExtractAll( @"c:\path\to\unzip\directory\", ExtractExistingFileAction.Throw ) ;
    }
    

    In my experience, DotNetZip runs about as fast as Info-Zip's open source unzip utility and uses roughly the same amount of memory.


    Edited To Note: DotNetZip used to live at Codeplex. Codeplex has been shut down. The old archive is still available at Codeplex. It looks like the code has migrated to Github:

    • https://github.com/DinoChiesa/DotNetZip. Looks to be the original author's repo.
    • https://github.com/haf/DotNetZip.Semverd. This looks to be the currently maintained version. It's also packaged up an available via Nuget at https://www.nuget.org/packages/DotNetZip/

    0 讨论(0)
提交回复
热议问题