none
MS Word document protection RRS feed

  • Question

  • Hi,

    I generate docx files as output from my tool. I would like to add document protection into docx.

    According ECMA specification I want to use SHA-1 encryption. The sample for "test" password and "foo" salt is:

    <w:documentProtection

    w:enforcement="1"

    w:edit="forms"

    w:cryptProviderType="rsaFull"

    w:cryptAlgorithmClass="hash"

    w:cryptAlgorithmType="typeAny"
    w:cryptAlgorithmSid="4"

    w:cryptSpinCount="1"
    w:hash="uPlhSA7DpYSaAKL6AjGwy2MQfHs="

    w:salt="Zm9v"/>

    w:hash was generated by command: $ echo -n footest | openssl dgst -binary -sha1 | openssl base64

    w:salt was generated by command: $ echo -n foo | base64

    This sample is the only output which is able to force MS Word 2010 to ask user for a password. But it doesn't accept "test" as password. What I'm doing wrongly?

    There is also strange thing. If w:cryptSpinCount or w:salt is omitted, MS Word doesn't even ask for password. It seems to be a bug, as specification says that those attributes are optional.

    Thank you for any help,

    Pavel


    Tuesday, February 16, 2016 10:28 AM

Answers

  • Hi Pavel,

    The documentProtection element specifies the set of document protection restrictions which have been applied to
    the contents of a WordprocessingML document. These restrictions should be enforced by applications editing this document when the enforcement attribute is turned on, and ignored (but persisted) otherwise. Document protection is a set of restrictions used to prevent unintentional changes to all or part of a WordprocessingML document.

    This feature is different with the encrypt document with password which will ask the password for the users when we open the document.

    >>This sample is the only output which is able to force MS Word 2010 to ask user for a password. But it doesn't accept "test" as password. What I'm doing wrongly?

    To narrow down this issue, I suggest that you add the editing restricting manually for the password "test" to see whether it works. And base on the test, the "test" password works well for me in Word 2010.

    Here is XML for your reference:

    <w:documentProtection w:edit="forms" w:enforcement="1" w:cryptProviderType="rsaFull" w:cryptAlgorithmClass="hash" w:cryptAlgorithmType="typeAny" w:cryptAlgorithmSid="4" w:cryptSpinCount="100000" w:hash="5fexC0/ZxpSbI/c6q/69c3UVW7k=" w:salt="ZF2BnGEqGIzstB+/z0h+kw==" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" />

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 17, 2016 6:09 AM
    Moderator