2013-06-24 95 views
1

所以我尋找一個簡單的答案,如何生成哈希和鹽保護docx4j庫選項的選項?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文件。

+0

驅動你尋找文件的比較?我有同樣的問題! http://stackoverflow.com/questions/13411678/docx4j-giving-wrong-result –

+0

那麼當你翻譯C#代碼時出了什麼問題?也許你應該將這些代碼添加到你的問題中。 – JasonPlutext

回答