I am implementing AES Algorithm 128 bit key. After encryption, the first 16 bytes of encrypted data will be stored in a .docx file. After that the .docx file will be blocked.
我正在实现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);
1 个解决方案
#1
1
As per what I understand from your comment, you want to encrypt your word file. You can achieve that using following code snippet:
根据我的评论你理解,你想加密你的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();
#1
1
As per what I understand from your comment, you want to encrypt your word file. You can achieve that using following code snippet:
根据我的评论你理解,你想加密你的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();