为什么我的 zip 文件夹没有用密码锁定,但里面的文件却被锁定了?

Why is my zip folder not locked with password, but the files inside are locked?

我已经苦苦挣扎了几个小时,试图在 zip 文件夹上设置密码。 然而,无论我尝试使用不同的代码多少次,密码都会应用于 zip 文件夹中的每个文件,这不是我想要的。我只想对文件夹本身应用密码,不应该为里面的单个文件设置密码。

这是我的代码:(供您参考,我使用的是 DotNetZip)

//Assume that there is a folder with multiple files in it at C:\ExampleFolder
using (Ionic.Zip.ZipFile z = Ionic.Zip.ZipFile())
{
    z.Password = "MyPassword";            //Setting the password
    z.AddDirectory(@"C:\ExampleFolder"); //I thought the directory added here should be pw-protected
    z.Save(@"C:\FinalResult.zip");       //Create the pw-protected zip folder
}

但是,当我 运行 这个程序时,它确实创建了一个名为 FinalResult.zip 的 zip 文件夹,但该 zip 文件夹没有密码保护。该 zip 文件夹中的所有文件均受密码保护。如果是这样,用户每次尝试打开里面的文件时都必须输入密码,这有点不方便。我只希望用户在尝试打开 zip 文件夹时只需输入一次密码。 谁能告诉我为什么这段代码不能实现我想要实现的目标?

密码实际工作正常:

When writing a zip archive, this password is applied to the entries, not to the zip archive itself. It applies to any ZipEntry subsequently added to the ZipFile, using one of the AddFile, AddDirectory, AddEntry, or AddItem methods, etc. When reading a zip archive, this property applies to any entry subsequently extracted from the ZipFile using one of the Extract methods on the ZipFile class.

请参阅 DotNetZip

Password 文档中的备注部分

https://documentation.help/DotNetZip/4444d7a5-3324-8af9-3ed3-5bf6551d3cd1.htm