【问题标题】:Apache POI decrypt doc file cannot process encrypted file?Apache POI 解密 doc 文件无法处理加密文件?
【发布时间】:2015-07-28 12:25:36
【问题描述】:
public static void decryptedDoc(String path,String[] password) throws FileNotFoundException, IOException{
  FileOutputStream fileOut = null;
  for(int i=0;i<password.length;i++){
//  try{
  Biff8EncryptionKey.setCurrentUserPassword(password[i]);
  NPOIFSFileSystem fs = new NPOIFSFileSystem( new FileInputStream(path));
  HWPFDocument doc=new HWPFDocument(fs.getRoot());
  Biff8EncryptionKey.setCurrentUserPassword(null);
  String neweachpath=path.substring(0, path.length()-4)+"_decrypted"+path.substring(path.length() -4);
  fileOut = new FileOutputStream(neweachpath);
  doc.write(fileOut);
  fileOut.flush(); 
  //}
 /* catch (EncryptedDocumentException e){
      System.out.println("wrong password for"+path+password[i]);
  }*/
  }

我想使用此代码来解密 doc 文件。

我从 Apache POI Encryption 引用了这段代码。它真正适用于 docx 和 xls、xlsx 文件。但是这里不行,即使密码正确也总是出现如下异常。

org.apache.poi.EncryptedDocumentException:无法处理加密 单词文件

钥匙好像没设置好。

【问题讨论】:

标签: java encryption apache-poi doc


【解决方案1】:

如您在问题中链接到的Apache POI Encryption page 中的图表所示:

处理 Word .doc 文件的 Apache POI 组件 HWPF 不支持解密受密码保护的 .doc 文件。因此,如果你尝试(如你所愿),你会得到一个例外

如表所示,所有基于 OOXML 的格式都以加密/密码保护的形式得到支持,因为它们都使用一种通用的方式来存储受保护的内容。旧的文件格式都有自己的处理方式,这需要对每种格式进行独立的实现。在 HSSF 中支持最常用的 xls 类型,在 HSLF 中支持 ppt 中使用的一种类型,但在 HWPF 中不支持 doc

如果这对您来说真的很重要,您需要通读 Microsoft 发布的文件格式文档以了解 .doc 文件如何进行加密,然后添加支持并回馈。 Apache POI - Contribution Guidelines page中提供了相关链接

【讨论】:

  • 非常感谢。我会尝试找出是否有其他库支持这个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-10
  • 1970-01-01
  • 2015-02-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多