.net core 为zip文件设置密码

.net core 为zip文件设置密码,.net-core,zipfile,.net Core,Zipfile,我正在尝试使用带有.Net核心的库为zip文件设置密码。 我按照示例设置密码,但是一旦创建了zip文件,文件就在其中,zip文件也在创建中,但是没有密码 // Create a password for the Zipfolder // https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples using (ICSharpCode.SharpZipLib.Zip.ZipFile ZipFile = new ICSharpCode.Sh

我正在尝试使用带有.Net核心的库为zip文件设置密码。

我按照示例设置密码,但是一旦创建了zip文件,文件就在其中,zip文件也在创建中,但是没有密码

// Create a password for the Zipfolder
// https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples
using (ICSharpCode.SharpZipLib.Zip.ZipFile ZipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(Path.GetFileName(destinationPath)))
{
     ZipFile.Password = "foo";
     ZipFile.Add(destinationPath, "");
}

我使用了维基上的例子,它没有问题

代码:


您只需要输入
BeginUpdate()
CommitUpdate()
,这将反映在您的输出中

using (ICSharpCode.SharpZipLib.Zip.ZipFile ZipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(Path.GetFileName(destinationPath)))
{
    ZipFile.BeginUpdate();
    ZipFile.Password = "foo";
    ZipFile.Add(destinationPath, "");
    ZipFile.CommitUpdate();
}

上述答案都不适用于我,
尽管如此,我还是在SharpZipLib库中找到了适合我的Fast Zip类

// Create a password for the Zipfolder
// https://github.com/icsharpcode/SharpZipLib/wiki
ICSharpCode.SharpZipLib.Zip.FastZip zipFile = new ICSharpCode.SharpZipLib.Zip.FastZip();
zipFile.Password = "foo";
zipFile.CreateEmptyDirectories = true;
zipFile.CreateZip(destinationPath,tempPath, true, "");

但我唯一不喜欢的是它没有实现

你测试过这个是吗?似乎没有密码。尝试此操作后仍然没有密码。是否尝试解压缩zip文件?当你打开zip文件时,他没有要求,所以文件名是readable@Lord_Pinhead即使受pw保护,zip文件列表也始终可见。
// Create a password for the Zipfolder
// https://github.com/icsharpcode/SharpZipLib/wiki
ICSharpCode.SharpZipLib.Zip.FastZip zipFile = new ICSharpCode.SharpZipLib.Zip.FastZip();
zipFile.Password = "foo";
zipFile.CreateEmptyDirectories = true;
zipFile.CreateZip(destinationPath,tempPath, true, "");