2

我想创建受密码保护的 ZIP:

// Set the compression level
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

// Set the encryption flag to true
// If this is set to false, then the rest of encryption properties are ignored
parameters.setEncryptFiles(true);

// Set the encryption method to Standard Zip Encryption
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);

// Set password
parameters.setPassword(password);

但这只是加密 zip 内的文件,但我可以打开这个 zip 并观看其中的文件。这不是我想要的,我想要保护 zip 密码而不是其中的文件。

4

1 回答 1

1

不可能,对不起。

诸如此类的文件不符合 .ZIP 文件格式规范。它指出,虽然实际文件已加密,但元数据(包括文件名和大小)加密。这一直是一个争论的话题,但事实就是这样。它的用途之一是您获得漂亮的“密码不正确”而不是垃圾文件。

无论哪种方式 - 不要依赖 .zip 文件加密。这很糟糕。不,真的-非常非常糟糕。它容易受到一整套攻击。

如果您想要一个正确加密的 .zip 文件 - 就这样做。制作一个 .zip 文件,然后使用适当的加密来制作一个加密文件。Java为此提供了很多加密工具。

于 2014-12-10T13:37:55.727 回答