這裏的ZIP文件規範:
Flags General purpose bit flag:
Bit 00: encrypted file
Bit 01: compression option
Bit 02: compression option
Bit 03: data descriptor
Bit 04: enhanced deflation
Bit 05: compressed patched data
Bit 06: strong encryption
Bit 07-10: unused
Bit 11: language encoding
Bit 12: reserved
Bit 13: mask header values
Bit 14-15: reserved
所以,9:1的GPBF值既具有「加密文件」,並設置「數據描述符」位。
在Android源代碼這裏一個偷看: https://chromium.googlesource.com/android_tools/+/9e9b6169a098bc19986e44fbbf65e4c29031e4bd/sdk/sources/android-22/java/util/zip/ZipFile.java (舊版本,但我懷疑這並沒有改變)顯示了這一點:
static final int GPBF_ENCRYPTED_FLAG = 1 << 0;
[...]
/**
* Supported General Purpose Bit Flags Mask.
* Bit mask of bits not supported.
* Note: The only bit that we will enforce at this time
* is the encrypted bit. Although other bits are not supported,
* we must not enforce them as this could break some legitimate
* use cases (See http://b/8617715).
*/
static final int GPBF_UNSUPPORTED_MASK = GPBF_ENCRYPTED_FLAG;
[...]
// At position 6 we find the General Purpose Bit Flag.
int gpbf = Short.reverseBytes(is.readShort()) & 0xffff;
if ((gpbf & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
}
所以,你的ZIP文件CL旨在對文件進行加密(設置GPBF的位00),並且ZipFile實現不支持讀取加密文件。
好的,你說特定的文件是加密的,它不能讀取它? –
是的,這就是我看起來的樣子。你是否試過(a)用不同的工具解壓縮同一個文件,和/或(b)用你的代碼解壓縮一個已知好的(未加密的)文件? –