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]);
}*/
}
我想利用這個代碼解密文檔文件。Apache POI解密doc文件無法處理加密文件?
我引用此代碼從Apache POI Encryption。它真正適用於docx和xls,xlsx文件。但它在這裏不起作用,即使密碼正確,也總是有以下例外。
org.apache.poi.EncryptedDocumentException:無法處理加密 word文件
看來鍵沒有正確設置。
我在此期間實現瞭解密/加密 - 檢查[工廠類](https://stackoverflow.com/questions/45238486#45337641)以處理doc/docx – kiwiwings