0

我正在实现 AES 算法 128 位密钥。加密后,前 16 个字节的加密数据将存储在 .docx 文件中。之后,.docx 文件将被阻止。

XWPFDocument document = new XWPFDocument() ;
FileOutputStream out = new FileOutputStream(filename,true);//filename is .docx word document
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText(ress1);//ress1 is a String datatype
document.write(out);
4

1 回答 1

1

根据我从您的评论中了解到的情况,您想加密您的 word 文件。您可以使用以下代码片段来实现:

POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile);

Encryptor enc = info.getEncryptor();
enc.confirmPassword(<your_password>);


OPCPackage opc = OPCPackage.open(new File(<file_path>), PackageAccess.READ_WRITE); //opening package for encryption 
OutputStream os = enc.getDataStream(fs); //perform encryption 
opc.save(os); //save package
opc.close();

FileOutputStream fos = new FileOutputStream("file_path"); 
fs.writeFilesystem(fos); //write the file back to file system
fos.close();
于 2016-06-29T19:42:57.343 回答