【发布时间】:2011-01-03 13:20:22
【问题描述】:
我正在开发一个需要解压缩 AES-256 加密 zip 文件的 android 应用程序,有没有我可以使用的库来完成此操作?
我非常感谢任何指导或帮助。
【问题讨论】:
标签: java android zip compression aes
我正在开发一个需要解压缩 AES-256 加密 zip 文件的 android 应用程序,有没有我可以使用的库来完成此操作?
我非常感谢任何指导或帮助。
【问题讨论】:
标签: java android zip compression aes
zip4j,用于处理 Zip 文件的 java 库(开源,Apache License v2.0)。
您可以下载二进制文件、源代码和示例。
【讨论】:
【讨论】:
这取决于您对加密 zip 文件的编码。请更具体。 如果它的压缩然后加密然后你解压缩然后解密文件使用java.util.zip.GZIPInputStream
【讨论】:
据我所知,AES 加密的 ZIP 文件是几年前由 WinZip 首次引入的。 在 WinZip 主页上有详细说明 AES 加密的 ZIP 文件与标准 ZIP 文件的不同之处:
【讨论】:
我正在开发一个普通的 JRE。使用http://www.lingala.net/zip4j/,下面的代码可以解密一个zip文件:
ZipFile zipFile = new ZipFile(zipFile);
zipFile.setPassword(password);
for (Object fileHeaderObj : zipFile.getFileHeaders()) {
FileHeader fileHeader = (FileHeader) fileHeaderObj;
String fileName = fileHeader.getFileName();
ZipInputStream zipIn = zipFile.getInputStream(fileHeader);
// do whatever with the input stream
}
【讨论】:
我遇到了类似的问题,并进行了很多搜索并测试了所有这些解决方案,但它们对我没有帮助。 最后,我找到了一个解决方案,我想在这里分享一下,也许它可以帮助其他人。
就我而言,我有一个 AES-256 加密的 zip 文件。
当我使用 zip4j 的最后一个版本时,我遇到了这个异常:
Zip4j 不支持强加密
zip4j 代码:
net.lingala.zip4j.ZipFile zipFile = new ZipFile("sourceAddress", "password".toCharArray());
zipFile.extractAll("destinationAddress");
之后我测试了 winzipaes 并遇到了这个错误:
额外字段的长度为 0 - 这可能不是 WinZip AES 加密条目
winzipaes 代码:
final File dbFile = new File("destinationFile");
AesZipFileDecrypter ze = null;
try {
ze = new AesZipFileDecrypter(new File("sourceAddress"), new AESDecrypterBC());
ExtZipEntry entry = ze.getEntry(dbFile.getName());
ze.extractEntry(entry, dbFile, "password");
} catch (DataFormatException | IOException e) {
e.printStackTrace();
} finally {
if (ze != null) {
try {
ze.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
最后,我找到了sevenzipjbind,它对我有用。
最终代码:
RandomAccessFile randomAccessFile = null;
IInArchive inArchive = null;
try {
randomAccessFile = new RandomAccessFile(fileAddress, "r");
inArchive = SevenZip.openInArchive(null, // autodetect archive type
new RandomAccessFileInStream(randomAccessFile));
// Getting simple interface of the archive inArchive
ISimpleInArchive simpleInArchive = inArchive.getSimpleInterface();
System.out.println(" Hash | Size | Filename");
System.out.println("----------+------------+---------");
for (ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
final int[] hash = new int[] { 0 };
if (!item.isFolder()) {
ExtractOperationResult result;
result = item.extractSlow(new ISequentialOutStream() {
public int write(byte[] data) throws SevenZipException {
InputStream myInputStream = new ByteArrayInputStream(data);
try {
byte[] buffer = new byte[myInputStream.available()];
myInputStream.read(buffer);
File targetFile = new File(destinationAddress + item.getPath());
OutputStream outStream = new FileOutputStream(targetFile);
outStream.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
return data.length; // Return amount of consumed data
}
},password);
if (result == ExtractOperationResult.OK) {
System.out.printf("%9X | %s%n",
hash[0], item.getPath());
} else {
System.err.println("Error extracting item: " + result);
}
}
}
} catch (Exception e) {
System.err.println("Error occurs: " + e);
} finally {
if (inArchive != null) {
try {
inArchive.close();
} catch (SevenZipException e) {
System.err.println("Error closing archive: " + e);
}
}
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (IOException e) {
System.err.println("Error closing file: " + e);
}
}
}
【讨论】:
我还没有测试过,但前段时间我发现了this。
希望对你有帮助
【讨论】: