当我加密一个简单的文档文件时。像这样
可以在Microsoft Word中打开。当我像这样更改另一个复杂的文档文件时
无法在 Microsoft Word 中打开。我不知道为什么。
public static boolean encrypDOC(String sourceFilePath, OutputStream out, String password) throws IOException {
POIFSFileSystem fs = null;
HWPFDocument doc = null;
try {
fs = new POIFSFileSystem(new FileInputStream(sourceFilePath));
doc = new HWPFDocument(fs);
Biff8EncryptionKey.setCurrentUserPassword(password);
doc.write(out);
return true;
} catch (Exception e) {
return false;
} finally {
doc.close();
fs.close();
out.close();
}
}