简体   繁体   English

无法使用 DotNetZip 设置密码

[英]Can't set password using DotNetZip

I'm trying to password protect a zip file using DotNetZip.我正在尝试使用 DotNetZip 密码保护 zip 文件。 But it doesn't work.但它不起作用。 It creates the zip just fine, but if i open it using 7zip I can extract the files without a password.它可以很好地创建 zip,但如果我使用 7zip 打开它,我可以在没有密码的情况下提取文件。 Here is the code I'm using.这是我正在使用的代码。

        using (ZipFile zip = new ZipFile())
        {
            zip.Password = password;
            zip.Encryption = EncryptionAlgorithm.WinZipAes256;
            zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;

            // Adding folders in the base directory
            foreach (var item in Directory.GetDirectories(someFilePath))
            {
                string folderName = new DirectoryInfo(item).Name;
                zip.AddDirectory(item, folderName);
            }

            // Adding files in the base directory
            foreach (string file in Directory.GetFiles(someFilePath))
            {
                zip.AddFile(file, "");
            }
            zip.Save(someFilePath);
        }

Okay, I fixed it.好的,我修好了。 I downloaded an older version of the DotNetZip dll.我下载了旧版本的 DotNetZip dll。

I was previously using version 1.12 and it didn't work.我以前使用的是 1.12 版,但没有用。

Using version 1.10.1 and the created zip is password protected使用版本 1.10.1 并且创建的 zip 文件受密码保护

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM