1

I use SharpZipLib to unzip files. For this, I use this code:

    using (var fsInput = File.OpenRead(zipFile))
    using (var zf = new ZipFile(fsInput)) {
        zf.Password = password;
                
        foreach (ZipEntry zipEntry in zf) {
            if (!zipEntry.IsFile) {
                // Ignore directories
                continue;
            }
                    
            var entryFileName = zipEntry.Name;

            // Manipulate the output filename here as desired.
            var fullZipToPath = Path.Combine(Settings.Default.ConsTemp, entryFileName);

            // 4K is optimum
            var buffer = new byte[4096];

            // Unzip file in buffered chunks. This is just as fast as unpacking
            // to a buffer the full size of the file, but does not waste memory.
            // The "using" will close the stream even if an exception occurs.
            using (var zipStream = zf.GetInputStream(zipEntry))
            using (Stream fsOutput = File.Create(fullZipToPath)) {
                StreamUtils.Copy(zipStream, fsOutput, buffer);
            }
        }
    }

I always the Exception Invalid password. When I try the same password for unzip in Windows, it works correctly.

Does anyone have any idea what could be the problem with SharpZipLib not using the password correctly?

BennoDual
  • 5,865
  • 15
  • 67
  • 153

0 Answers0