Andreas,
Thanks for quick help!
Following are the answer for you asking's
Can you provide me a failing .doc file? That are attached please find the
same(password: 123456).
So reading/writing the .docx files works, right? Yes, am able read the .docx
file but not able to write.
In addition I have added the code which I have written the to read docx and doc
both.
Sample Code:-
FileInputStream fis = new FileInputStream("sample1.doc");
try {
fs = new POIFSFileSystem(fis);
System.out.println("File is password protected");
EncryptionInfo info = new EncryptionInfo(fs); //It will throw
exception(posted below) at this line, but if we pass .docx file to
FileInputStream it will work properly.
Decryptor d = Decryptor.getInstance(info);
if (d.verifyPassword("123456")) {
InputStream dataStream = d.getDataStream(fs);
document = new XWPFDocument(dataStream);
} else {
throw new ApplicationException("Unable to process:
wrong password ");
}
} catch (OfficeXmlFileException e) {
System.out.println("File is Not password protected");
document = new
XWPFDocument(POIXMLDocument.openPackage(srcPath));
}
Exception thrown is:-
java.io.FileNotFoundException: no such entry: "EncryptionInfo"
Thanks and Regards,
Ajeet Singh
-----Original Message-----
From: Andreas Beeker [mailto:[email protected]]
Sent: Friday, August 01, 2014 11:55 AM
To: POI Developers List
Subject: Re: Creating encrypted documen(.doc and .docx)
> I have to read an encrypted file and write the content of that file in
> new file with some modification and with same password protection
> While using EncryptionInfo we are able to read .docx file but it's not
> working if we use it for .doc
Currently the CryptoAPI method is not supported. Maybe your .doc file is using
this encryption method.
Furthermore the XOR obfuscation differs slightly for .xls and .doc files, and I
have only tested/developed it with .xls files :| ... and afaik both RC4/XOR
methods are record based encryption opposed to standard/agile encryption where
the whole file is encrypted in one stream, so POI supports it only for .xls
Can you provide me a failing .doc file?
So reading/writing the .docx files works, right?
MASTEK LTD.
In the US, we're called MAJESCOMASTEK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of
Mastek Limited, unless specifically indicated to that effect. Mastek Limited
does not accept any responsibility or liability for it. This e-mail and
attachments (if any) transmitted with it are confidential and/or privileged and
solely for the use of the intended person or entity to which it is addressed.
Any review, re-transmission, dissemination or other use of or taking of any
action in reliance upon this information by persons or entities other than the
intended recipient is prohibited. This e-mail and its attachments have been
scanned for the presence of computer viruses. It is the responsibility of the
recipient to run the virus check on e-mails and attachments before opening
them. If you have received this e-mail in error, kindly delete this e-mail from
desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]