简体   繁体   中英

Can't set password using DotNetZip

I'm trying to password protect a zip file using DotNetZip. 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. 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.

I was previously using version 1.12 and it didn't work.

Using version 1.10.1 and the created zip is password protected

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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