Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zip files in .net core with password

I'm trying to generate zip (or other compression formats) files in .net core with password, but I can't find any tool that does not come without a cost.

I've tried System.IO.Compression but it doesn't have a method with password.

like image 773
Johna Avatar asked Mar 27 '17 19:03

Johna


1 Answers

Good news is that DotNetZip supports .net Core now. Check Nuget for more details. (Meanwhile System.IO.Compression still doesn't support password protection)

I've used 1.16.0 version in .Net Core 3.1 and it works well.

Brief tutorial:

using (var zip = new ZipFile())
                {
                    zip.Password = pwd;
                    zip.AddEntry(FileA_Name, FileA_Content);
                    zip.AddEntry(FileB_Name, FileB_Content);
                    MemoryStream output = new MemoryStream();
                    zip.Save(output);
                    return File(output.ToArray(), "application/zip", Zip_Name);
                }

Don't forget to add DotNetZip Nuget package in your project, and import using Ionic.Zip;

like image 197
亞鯉斯多德 Avatar answered Sep 21 '22 11:09

亞鯉斯多德