Mac下使用自带的归档实用工具解压加密zip的问题

rage_angel 2016-09-14 11:05:21
问题描述:我用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();
}
}

```

```

...全文
1329 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,545

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧