1

所以我寻找简单的答案,如何使用 docx4j 库为单词保护选项生成哈希和盐?

我得到了这个方法:

public static void setUpReadOnlyDocumentWithPassword(DocumentSettingsPart documentSettingsPart, String password) {
    final CTSettings settings = Context.getWmlObjectFactory().createCTSettings();
    final CTDocProtect protection = Context.getWmlObjectFactory().createCTDocProtect();
    protection.setEdit(STDocProtect.READ_ONLY);
    protection.setFormatting(true);
    protection.setEnforcement(true);
    protection.setCryptProviderType(STCryptProv.RSA_FULL);
    protection.setCryptAlgorithmClass(STAlgClass.HASH);
    protection.setCryptAlgorithmType(STAlgType.TYPE_ANY);
    protection.setCryptAlgorithmSid(new BigInteger("4"));
    protection.setCryptSpinCount(new BigInteger("100000"));
    protection.setHash(?????);
    protection.setSalt(?????);
    settings.setDocumentProtection(protection);
    documentSettingsPart.setJaxbElement(settings);
}

我真的尝试了一切,甚至从http://social.msdn.microsoft.com/Forums/vstudio/en-US/63588f50-354f-43ba-b080-e0e6c51a0fb5/hash-and-saltdocumentprotection翻译 C# 代码。我想完全自动化为 docx 文件设置密码。

4