如何在 Java 中解压缩加密的 ODT OpenDocument [英] how to unzip an encrypted ODT OpenDocument in Java

查看:30
本文介绍了如何在 Java 中解压缩加密的 ODT OpenDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个加密的 ODT(开放文档文本)文件,我需要解压缩它.ODT 是一个 ZIP 文件.加密的 ODT 是一个普通的 ZIP 文件,只是 ZIP 中的一些文件被加密了.

I have an encrypted ODT (Open Document Text) file and I need to unzip it. ODT is a ZIP file. An encrypted ODT is a normal ZIP file, just some files inside the ZIP are encrypted.

使用 ZipFile 在测试中可以正常工作,但我真的不能使用 ZipFile,因为我在内存中有一个流,我不想使用文件.

Using ZipFile works okay in a test, but I cannot use ZipFile really because I have a stream in memory, I don't want to work with a file.

因此我使用 ZipInputStream.但是使用 ZipInputStream.getNextEntry() 会抛出可怕的只有 DEFLATED 条目可以有 EXT 描述符例外.

Therefore I use ZipInputStream. But using ZipInputStream.getNextEntry() throws the dreadful only DEFLATED entries can have EXT descriptor exception.

据我所知,它抛出 ZIP 包内的第一个加密文件,例如 content.xml.因为 OpenOffice 已经加密了 xml 文件,所以压缩它可能没有意义,它被存储在未压缩的 ZIP 包中.

From what I can understand, it throws on the first encrypted file inside the ZIP package, for example on content.xml. Because OpenOffice has encrypted the xml file, it was probably no point compressing it and it was stored inside the ZIP package uncompressed.

但 ZipInputStream 似乎有问题,我没有找到解决办法.

But ZipInputStream seems to have a problem with it and I don't see a way around.

是的,加密的 ODT 文件是由 OpenOffice Writer 3.2.1 创建的.是的,库存 ZipInputStream 甚至无法枚举其中的条目.

And yes, the encrypted ODT file was created by OpenOffice Writer 3.2.1. And yes, the stock ZipInputStream cannot even enumerate through entries in it.

您有什么建议吗?

推荐答案

该问题与加密无关,而是与 ZipInputStream 在关联时不期望(也不知道如何处理)EXT 描述符有关数据未压缩(即未压缩存储,原样).这很可能是 ZipInputStream 中的一个缺陷(错误"),但我对 zip 规范不够熟悉,无法了解一种或另一种方式.

The problem has nothing to do with encryption, but with the fact that ZipInputStream does not expect (and does not know how to handle) an EXT descriptor when the associated data was not DEFLATED (i.e. was stored uncompressed, as-is). This may well be a deficiency ("bug") in ZipInputStream, but I am not familiar enough with the zip specs to know one way or another.

一种不优雅、甚至非常丑陋的解决方法是将流持久化到一个临时文件中,然后将其作为 ZipFile 进行处理.

An inelegant, even downright ugly workaround is to persist the stream to a temporary file, and then process it as a ZipFile.

(我是 ODFind 和上面提到的解密 ODF 文件"文档的作者.)

(I am the author of ODFind and the "Decrypting ODF Files" document mentioned above.)

这篇关于如何在 Java 中解压缩加密的 ODT OpenDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆