Hi Andy,
Incidentally my original code was trying to use ByteArrayOutputStream but like
this, I only changed it to open the file (the code POI suggests) to make sure I
wasnt doing anything wrong.
ByteArrayOutputStream encryptedOutputStream = new ByteArrayOutputStream();
try {
POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile);
Encryptor enc = info.getEncryptor();
enc.confirmPassword(reportPassword);
OPCPackage opc = OPCPackage.open(new
ByteArrayInputStream(excelOutputStream.toByteArray()));
OutputStream os = enc.getDataStream(fs);
opc.save(os);
opc.close();
fs.writeFilesystem(encryptedOutputStream);
} catch (Exception ex) {
But this gives me the same error I posted about the part being null.
Also, I tried to do something like this:
POIFSFileSystem fs = new POIFSFileSystem(inputStream);
EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile);
Encryptor enc = info.getEncryptor();
enc.confirmPassword("testPass");
However, I get the following exception:
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data
appears to be in the Office 2007+ XML. You are calling the part of POI that
deals with OLE2 Office Documents. You need to call a different part of POI to
process this data (eg XSSF instead of HSSF)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:133)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:106)
at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:128)
I tried something similar to what you posted but I was not able to encrypt the
file.
Any help would be great!
Thanks!
-----Original Message-----
From: Andreas Beeker [mailto:[email protected]]
Sent: Thursday, February 19, 2015 2:57 PM
To: POI Users List
Subject: Re: Unable to save a file exported by Jasper Report using OPCPackage
for encryption
Hi Jose,
does it work, if you simply copy the data into the encrypted outputstream?
something like:
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ...
exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, outputStream); ...
exporter.exportReport();
...
OutputStream os = enc.getDataStream(fs); bos.writeTo(os); ...
Best wishes,
Andi
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional
commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]