使用ICSharpCode.SharpZipLib的受密码解压缩的zip文件的问题 [英] problem with unzip password protected zip files using ICSharpCode.SharpZipLib
本文介绍了使用ICSharpCode.SharpZipLib的受密码解压缩的zip文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用一个循环,尝试输入给定的几个密码,直到其中一个打开文件而无需经历键入它们的过程.
但是我遇到了一个问题.如果程序尝试输入的第一个密码错误,则将提取压缩文件中的文件,但文件的容量为零.
并且我们遇到了访问被拒绝错误,这使得程序无法继续检查其他密码.
我该如何解决这个问题?
我感谢您的帮助.
这是解压缩方法:
public static void UnZipFiles(string zipPathAndFile, string outputFolder, string password, bool deleteZipFile) { ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile)); if (password != null && password != String.Empty) s.Password = password; ZipEntry theEntry; string tmpEntry = String.Empty; while ((theEntry = s.GetNextEntry()) != null) { string directoryName = outputFolder; string fileName = Path.GetFileName(theEntry.Name); // create directory if (directoryName != "") { Directory.CreateDirectory(directoryName); } if (fileName != String.Empty) { if (theEntry.Name.IndexOf(".ini") < 0) { string fullPath = directoryName + "\\" + theEntry.Name; fullPath = fullPath.Replace("\\ ", "\\"); string fullDirPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath); FileStream streamWriter = File.Create(fullPath); int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } streamWriter.Close(); } } } s.Close(); if (deleteZipFile) File.Delete(zipPathAndFile); } }
解决方案
您是否在尝试解压缩zip文件之前检查密码是否有效?
尝试在代码周围放置try/catch块,以查看失败的地方.
是的,我做到了
密码不匹配的异常会发生.
最后,我决定使用Codeplex中的dotNetZip组件
hi
i am using ICSharpCode.SharpZipLib utility for unziping password protected zip files.
i''m using a loop which tries a couple of passwords given till one of them opens the files without going through the process of typing them.
but i have faced a problem. if the first password the program tries is wrong then the files in the zipped file are extracted but the files have a zero capacity.
and we face the access denied error which makes the continuation of the program to check other passwords impossible.
how can i deal with this problem?
i appreciate your help.
here is the unzip method:
public static void UnZipFiles(string zipPathAndFile, string outputFolder, string password, bool deleteZipFile) { ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile)); if (password != null && password != String.Empty) s.Password = password; ZipEntry theEntry; string tmpEntry = String.Empty; while ((theEntry = s.GetNextEntry()) != null) { string directoryName = outputFolder; string fileName = Path.GetFileName(theEntry.Name); // create directory if (directoryName != "") { Directory.CreateDirectory(directoryName); } if (fileName != String.Empty) { if (theEntry.Name.IndexOf(".ini") < 0) { string fullPath = directoryName + "\\" + theEntry.Name; fullPath = fullPath.Replace("\\ ", "\\"); string fullDirPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath); FileStream streamWriter = File.Create(fullPath); int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } streamWriter.Close(); } } } s.Close(); if (deleteZipFile) File.Delete(zipPathAndFile); } }
解决方案
Are you checking to make sure the password is valid before trying to uncompress the zip file?
Try putting a try/catch block around the code to see where it''s failing.
yes i did
the password did not match exception will occur.
finally i decide to use dotNetZip component from codeplex
这篇关于使用ICSharpCode.SharpZipLib的受密码解压缩的zip文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文