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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With