As Gagravarr pointed out, the page for supported encryption / password protection matrix pretty much sums it up. With the standard library you won't be able to set a password.
You may have an option to implement it, if the details are described in the binary formats specification for the Word file format. Some years ago, I built a custom HWPF library for a client, so I spent a lot of time with analyzing the file format and reading the specs. However, I don't remember the sections about encryption / protection, probably because they were not relevant to me.
If it is possible to add protection with a reasonable amount of work:
.doc
files are stored in the OLE2 compound document format. This format contains the actual Word related data. (If you are new to this, you might think of it as an archiver format - maybe like a ZIP file without compression.) The OLE2 part is well supported (module POIFS
). The binary Word file format (module HWPF
) is not so well supported. If you read a Word file into a HWPFDocument
and write that out again, you very likely end up with an invalid document.
So if it is possible to add protection without having to read and write out the HWPFDocument
, you have a chance. If modification of the Word data part is needed, and it is only small, maybe changing a couple of bytes (not inserting or removing) without reading and writing the HWPFDocument
, then you also have a chance. But if implementing the protection requires changes to a lot of Word file format structures, you likely won't finish this part of the project within months (maybe years, if you are a one-man-team :-) ).