问题描述:我用java生成了一个加密的zip包,用的是AesZipFileEncrypter来实现的,但是这个zip包不能用Mac自带的归档实用工具直接打开,会报“无法将xx.zip解压缩到xx(错误1-操作不被允许)”。
用The Unarchiver可以解压,该怎么解决用Mac自带的“归档实用工具”打开加密zip包的问题呢?
已验证:同样的,用java生成的这个zip包,通过命令unzip xx.zip也是打不开的。会报“unsupported compression method 99”的错误。
但是如果我用zip命令生成一个加密的压缩包,就可以通过unzip的命令来解开。而且也可以通过Mac自带的“归档实用工具”双击打开。
有谁遇到同样的问题吗?用java该怎么写才能够生成系统自带的工具就可以打开而不需要安装第三发解压软件?
生成加密zip的代码如下:
@Test
public void zipTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// AesZipFileEncrypter_Override aesZip;
AesZipFileEncrypter aesZip;
AESEncrypterBC encrypterBC = new AESEncrypterBC();
try {
String storePass = "123";
encrypterBC.init(storePass, 0);
aesZip = new AesZipFileEncrypter(outputStream, encrypterBC);
// aesZip.setEncoding("GBK");
String cn = "www.test.com";
String certStr = "111111kcjasckjdkslncksdjbcvjksdfbvjdfhsbvhf";
String newKey = "222222kcjasckjdkslncksdjbcvjksdfbvjdfhsbvhf";
String caStr = "333333kcjasckjdkslncksdjbcvjksdfbvjdfhsbvhf";
aesZip.add(cn + ".cer", new ByteArrayInputStream(certStr.getBytes()), storePass);
aesZip.add(cn + ".key", new ByteArrayInputStream(newKey.getBytes()), storePass);
aesZip.add(cn + "_ca.crt", new ByteArrayInputStream(caStr.getBytes()), storePass);
aesZip.close();
outputStream.flush();
FileOutputStream fos = new FileOutputStream(new File("/Users/temp/test3.zip"));
fos.write(outputStream.toByteArray());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
```
```