在vb.net中测试zip密码的正确性
我想测试 zip 在 vb.net 中是否有特定的密码。如何创建像 check_if_zip_pass(file, pass) As Boolean
这样的函数?
我似乎无法在 .net 框架中找到任何已经执行此操作的内容,除非我遗漏了一些非常明显的内容。
此方法不应提取文件,仅在尝试的传递有效时返回 True
,否则返回 False
。
I want to test if a zip has a particular password in vb.net. How can I create a function like check_if_zip_pass(file, pass) As Boolean
?
I can't seem to find anything in the .net framework that does this already, unless I'm missing something incredibly obvious.
This method should NOT extract the files, only return True
if the attempted pass is valid and False
if not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 .NET 中使用 SharpZipLib 来执行此操作,这里有一个 链接 到他们的 wiki具有用于解压缩受密码保护的 zip 文件的帮助函数。下面是 VB.NET 辅助函数的副本。
为了进行测试,您可以创建一个文件比较,在压缩之前和解压之后再次查看文件(大小、日期等...)。如果您想使用简单的测试文件(例如内部带有文本“TEST”的文件),您甚至可以比较内容。有很多选择,取决于您想要测试的程度和程度。
I use SharpZipLib in .NET to do this, here is a link to their wiki with a helper function for unzipping password protected zip files. Below is a copy of the helper function for VB.NET.
To test, you could create a file compare that looks at the file before it's zipped and again after it has been unzipped (size, date, etc...). You could even compare the contents if you wanted to use a simple test file, like a file with the text "TEST" inside. Lots of choices, depends on how much and how far you want to test.
框架中并没有内置太多用于执行此操作的内容。这是一个很大的混乱,您可以尝试使用 SharpZipLib 库:
Apologies for the C#;转换为 VB.NET 应该相当简单。
There's not much built into the framework for doing this. Here's a big sloppy mess you could try using the SharpZipLib library:
Apologies for the C#; should be fairly straightforward to convert to VB.NET.
使用第 3 方库,例如 DotNetZip。请记住,zip 文件中的密码适用于条目,而不是整个 zip 文件。所以你的测试不太有意义。
WinZip 可能拒绝解压 zip 文件的一个原因是第一个条目受密码保护。可能只有某些条目受密码保护,而另一些则不受密码保护。不同的条目可能使用不同的密码。您必须决定如何应对这些可能性。
一种选择是假设 zip 文件中加密的任何条目仅使用一个密码。 (zip 规范不要求这样做)在这种情况下,下面是一些用于检查密码的示例代码。如果不进行解密,就无法检查密码。所以这段代码解密并提取到 Stream.Null 中。
哎呀!我认为在 C# 中。在 VB.NET 中,这将是:
Use a 3rd party library, like DotNetZip. Keep in mind that passwords in zipfiles are applied to entries, not to the entire zip file. So your test doesn't quite make sense.
One reason WinZip may refuse to unpack the zipfile is that the very first entry is protected with a password. It could be the case that only some entries are protected by password, and some are not. It could be that different passwords are used on different entries. You'll have to decide what you want to do about these possibilities.
One option is to suppose that only one password is used on any entries in the zipfile that are encrypted. (This is not required by the zip specification) In that case, below is some sample code to check the password. There is no way to check a password without doing the decryption. So this code decrypts and extracts into Stream.Null.
Whoops! I think in C#. In VB.NET this would be: