Apache的POI解密doc文件不能处理加密的文件? [英] Apache POI decrypt doc file cannot process encrypted file?

查看:3004
本文介绍了Apache的POI解密doc文件不能处理加密的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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]);
  }*/
  }

我想用这个code解密DOC文件。

I want to use this code to decrypt doc files.

我引用这个code从的Apache POI加密。它真正的作品为DOCX和XLS,XLSX文件。不过,这并不在这里工作,总是有以下异常,即使密码是正确的。

I referenced this code from Apache POI Encryption . It truly works for docx and xls, xlsx files. But it does not work here, always has the following exception even when the password is right.

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

org.apache.poi.EncryptedDocumentException: Cannot process encrypted word file

看来键没有正确设置。

推荐答案

由于覆盖图在阿帕奇你在你的问题联系到POI加密页面

HWPF,它处理的Word .DOC 文件的Apache POI组件,不支持保护解密密码 .DOC 文件。因此,如果你尝试,你会得到一个异常(你有)

HWPF, the Apache POI component which handles Word .doc files, does not support decrypting password protected .doc files. As such, you will get an Exception if you try (as you have)

如表中说明,所有的基于OOXML的格式在其加密/密码保护的形式被支持,因为这些都使用存储受保护内容的一种常见的方式。旧的文件格式,每个人都有自己的做事方式,这需要对每个独立的形式实现。还有的用于在HSSF XLS ,用于在HSLF 百分点使用的各种其中最常见的一种支持,但没有商务部支持HWPF。

As the table explains, all of the OOXML-based formats are supported in their encrypted / password protected form, as those all use a common way of storing the protected content. The older file formats each have their own way of doing things, which requires independent implementations for each format. There's support for the most common kind used for xls in HSSF, for one of the kinds used in ppt in HSLF, but no doc support in HWPF.

如果这真的对你很重要,你需要读通过微软发布的文件格式的文档摸出.doc文件怎么办加密,然后加在支持和促进了回去。对于在的Apache POI可链接 - 贡献准则

If this really matters to you, you'll need to read through the Microsoft published file format documentation to work out how .doc files do encryption, then add in the support and contribute it back. Links for that are available in the Apache POI - Contribution Guidelines page

这篇关于Apache的POI解密doc文件不能处理加密的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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