Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 11 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(9)
您可以尝试Zip4j,一个处理zip文件的纯java库。 支持PKWare和AES加密方式的加解密。
主要功能:
许可证:
You can try Zip4j, a pure java library to handle zip file. It supports encryption/ decryption of PKWare and AES encryption methods.
Key features:
License:
2020 年更新:现在还有其他选择,特别是 Zip4J。
经过大量搜索,我发现了三种方法:
一组免费的源代码,适用于单个文件 zip。 但是,没有许可证。 用法是 AesZipOutputStream.zipAndEcrypt(...)。
http://merkert.de/de/info/zipaes/src.zip
(https://forums.oracle.com/forums/thread.jspa?threadID= 1526137)
更新:此代码现已获得 Apache 许可并在 https://github.com/mobsandgeeks/ 发布winzipaes(从 Google 代码 的原始主页导出)。 它对我有用(zip 中的一个文件),并且很好地填补了 Java 开源库中的一个漏洞。
商业产品(撰写本文时价格为 500 美元)。 我无法验证这是否有效,因为他们的试用许可证方法很复杂。 它也是一个移植的 .NET 应用程序:
http://www.nsoftware.com/ipworks/zip/default.aspx
商业产品(撰写本文时 290 美元)。 仅适用于 Wnidows,因为它使用 dll:
http://www.example-code.com/java/zip.asp
UPDATE 2020: There are other choices now, notably Zip4J.
After much searching, I've found three approaches:
A freely available set of source code, suitable for a single file zip. However, there is no license. Usage is AesZipOutputStream.zipAndEcrypt(...).
http://merkert.de/de/info/zipaes/src.zip
(https://forums.oracle.com/forums/thread.jspa?threadID=1526137)
UPDATE: This code is now Apache licensed and released at https://github.com/mobsandgeeks/winzipaes (exported from original home at Google code) . It worked for me (one file in the zip), and fills a hole in Java's opens source libraries nicely.
A commercial product ($500 at the time of writing). I can't verify if this works, as their trial license approach is complex. Its also a ported .NET app:
http://www.nsoftware.com/ipworks/zip/default.aspx
A commercial product ($290 at the time of writing). Suitable only for Wnidows as it uses a dll:
http://www.example-code.com/java/zip.asp
这不是答案,但在评估潜在解决方案时要记住这一点。
关于 zip 加密的一件非常重要的事情是:
zip 加密有多种类型。 旧类型(原始 zip 标准的一部分)根本不值得费心(可以在 10 分钟内通过在线轻松获取的应用程序将其破解)。
如果您要对 zip 文件进行任何类型的加密,请务必使用强大的加密标准之一(我相信 WinZip 的 128 位和 256 位 AES 标准受到最好的支持)。 这里是技术规格 - 我们在开发自己的Java加密zip系统时使用了它(不能提供源代码 - 抱歉 - 仅供内部使用)
比没有加密更糟糕的唯一事情是认为你有加密并且是错误的:-)
This isn't an answer, but it is a caution to keep in mind when evaluating potential solutions.
One very important thing about zip encryption:
There are several types of zip encryption. The old type (part of the original zip standard) is not at all worth bothering with (it can be cracked in less than 10 minutes with apps easily available online).
If you are doing any sort of encryption of zip files, please, please be sure you use one of the strong encryption standards (I believe that WinZip's 128- and 256-bit AES standard is the best supported). Here are the technical specs - we used this when developing our own Java encrypted zip system (can't provide source - sorry - it's internal use only)
The only thing worse than having no encryption is thinking that you have encryption and being wrong :-)
7-Zip 可以选择在命令行模式下添加密码。 也许你可以执行它来获得这个结果(并且它也有很好的压缩比)。
缺点:外部进程,难以移植(即使 7-Zip 本身是可移植的),不确定分发许可证。
请注意,InfoZip 的 Zip 实用程序也具有高度可移植性,也支持密码。
7-Zip has the option to add a password in its command-line mode. Perhaps you can exec it to get this result (and it has a good compression ration too).
Drawbacks: external process, hard to make portable (even if 7-Zip is portable itself), not sure of distribution license.
Note that InfoZip's Zip utility, highly portable too, also supports password.
您也可以尝试 TrueZip。 请参阅以下链接了解功能:
https://christian-schlichtherle.bitbucket.io/truezip/
TrueZip 的后继者可以可以在这里找到:
https://christian-schlichtherle.bitbucket.io/truevfs/
You can also try TrueZip. See the following links for features:
https://christian-schlichtherle.bitbucket.io/truezip/
The successor of TrueZip can be found here:
https://christian-schlichtherle.bitbucket.io/truevfs/
以下是使用 winzipaes 1.0.1 的示例。
请注意,这只是一个要点,我尚未以这种形式测试此代码。
您可以在 Mac 上使用 Winzip (v9+) 或 7za(即 7zip)解压缩“/tmp/foo.zip”,使用密码“my-password”。
注意:我不清楚为什么需要在上面的代码中指定两次密码。 我不知道如果你在这两个地方使用不同的密码会发生什么。
Here's an example using winzipaes 1.0.1.
Note this is just a gist, I have not tested this code in exactly this form.
You can them unzip "/tmp/foo.zip" using Winzip (v9+) or 7za (i.e. 7zip) on a Mac, using password "my-password".
Note: it's not clear to me why it is necessary to specify the password twice in the code above. I do not know what would happen if you used different passwords in these two places.
如果你给出更好的使用场景那么还有其他替代方案。
对于 3,那么您可以使用 java 将 zip 的流内容加密为普通文件,可能最好将文件扩展名更改为 .ezip 或类似的文件。
对于 1 和 2,您可以使用上述的 chillkat 解决方案或等效解决方案。
但请注意 chillkat 不是纯 Java 解决方案,它使用 JNI。
If you give a better usage scenario then there are other alternatives.
For 3 then you can just use java to encrypt the stream contents of the zip as a normal file, probably best to change the file extension to .ezip or somesuch too.
For 1 and 2 then you can use the chillkat solution as mentioned, or an equivalent.
However be aware that chillkat is not a pure Java solution, it uses JNI.
附加信息:我用谷歌搜索了更多,事实上,这是一个非常常见的问题,而且似乎没有免费的解决方案(还?)。
现在,Zip 加密的标准算法已明确定义:请参阅 PKWARE 的 关于 .ZIP 文件格式的应用说明。 它似乎是对加密流进行的加密。 如果有人想对其进行编码...
现在,我想知道为什么 Sun 不将其包含在其库中? 缺乏标准? 专利/法律问题? 太弱了无法使用?
Additional info: I googled a bit more and indeed, it is a quite common question, and it appears there is no free solution (yet?).
Now, the standard algorithm of Zip encryption is well defined: See PKWARE's Application Note on the .ZIP file format. It appears to be an encryption done on the encrypted stream. If somebody feels like coding it...
Now, I wonder why Sun didn't include it in its library? Lack of standard? Patent/legal issue? Too weak to be usable?
java.util.zip 将执行压缩操作,但不会执行密码操作。 不,我不知道有任何免费的可以。 我见过的最便宜的开发人员席位是 150 美元。
java.util.zip will do the zipping, but it won't do the passwords. And no, I don't know of any free ones that will. The cheapest I've seen is $150 for a developer seat.