【发布时间】: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:无法处理加密 单词文件
钥匙好像没设置好。
【问题讨论】:
-
我同时实现了解密/加密 - 检查 the factory class 以处理 doc/docx
标签: java encryption apache-poi doc