【问题标题】:How to decompress an AES-256 Encrypted zip files?如何解压缩 AES-256 加密的 zip 文件?
【发布时间】:2011-01-03 13:20:22
【问题描述】:

我正在开发一个需要解压缩 AES-256 加密 zip 文件的 android 应用程序,有没有我可以使用的库来完成此操作?

我非常感谢任何指导或帮助。

【问题讨论】:

    标签: java android zip compression aes


    【解决方案1】:

    zip4j,用于处理 Zip 文件的 java 库(开源,Apache License v2.0)。

    http://www.lingala.net/zip4j/

    • 从 Zip 文件中创建、添加、提取、更新、删除文件
    • 读/写受密码保护的 Zip 文件
    • 支持 AES 128/256 加密
    • 支持标准 Zip 加密

    您可以下载二进制文件、源代码和示例。

    【讨论】:

    【解决方案2】:

    我最终在http://code.google.com/p/winzipaes/ 使用了一个外部库

    它仅限于压缩/解压缩使用 AES-256 加密的 Zip 文件

    但至少它符合我的需要。

    【讨论】:

      【解决方案3】:

      这取决于您对加密 zip 文件的编码。请更具体。 如果它的压缩然后加密然后你解压缩然后解密文件使用java.util.zip.GZIPInputStream

      【讨论】:

      • 感谢您的回答,但在我的问题中很明显我需要“解压缩加密的 zip 文件”我会更新我的 Q,非常感谢。
      • 我完全理解,但是这个使用特定格式的“加密压缩文件”,它是如何加密的? ECB、CBC、CTR 还是……? zip文件是存档吗?谁生成文件?它是如何产生的?等等...然后我可以给你发一个代码来使用。
      • 感谢您的回复,我尝试解压缩的加密 zip 文件是一个存档,并使用通过其他 Windows 应用程序构建的 AES-256 加密,我将在 Android 设备上下载它并进行解压缩阅读它的内容。
      • 然后找到一个库,否则这是一项艰巨的任务,因为这些档案允许不同的操作模式和不同的 AES-256 算法进行链接和填充!!!!
      【解决方案4】:

      据我所知,AES 加密的 ZIP 文件是几年前由 WinZip 首次引入的。 在 WinZip 主页上有详细说明 AES 加密的 ZIP 文件与标准 ZIP 文件的不同之处:

      http://www.winzip.com/aes_info.htm

      【讨论】:

      • 感谢您的链接,我已经在 iPhone 上实现了使用 AES-256 加密的 Zip 文件的解压缩,我确切地知道它是如何工作的,但现在我坚持使用 android 实现。
      【解决方案5】:

      我正在开发一个普通的 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
      }
      

      【讨论】:

        【解决方案6】:

        我遇到了类似的问题,并进行了很多搜索并测试了所有这些解决方案,但它们对我没有帮助。 最后,我找到了一个解决方案,我想在这里分享一下,也许它可以帮助其他人。

        就我而言,我有一个 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);
                    }
                }
            }
        

        【讨论】:

          【解决方案7】:

          我还没有测试过,但前段时间我发现了this

          希望对你有帮助

          【讨论】:

          • 感谢 maid450,但这不是我要找的,这是加密/解密字符串,我需要加密/解密 Zip 文件,感谢您的努力。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-01-20
          • 1970-01-01
          相关资源
          最近更新 更多