81,092
社区成员
发帖
与我相关
我的任务
分享
/ZIP解压
public static final String unzip(String compressedStr) {
if (compressedStr == null) {
return null;
}
ByteArrayOutputStream out = null;
ByteArrayInputStream in = null;
ZipInputStream zin = null;
String decompressed = null;
try {
//解开BASE64编码
byte[] compressed = new sun.misc.BASE64Decoder()
.decodeBuffer(compressedStr);
System.out.println(compressed);
//解密
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128, new SecureRandom("QMQWLBKK64WUS1W6".getBytes()));
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");// 创建密码器
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] result = cipher.doFinal(compressed);
//解密结束
out = new ByteArrayOutputStream();
in = new ByteArrayInputStream(result);
zin = new ZipInputStream(in);
while(zin.getNextEntry() != null){
byte[] buffer = new byte[result.length];
int offset = -1;
while ((offset = zin.read(buffer,0,buffer.length)) != -1) {
out.write(buffer, 0, offset);
}
}
decompressed = out.toString();
} catch (Exception e) {
e.printStackTrace();
decompressed = null;
} finally {
if (zin != null) {
try {
zin.close();
} catch (IOException e) {
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
return decompressed;
}