A simple question regarding password protection of docx document. The protection and the document is locked perfectly but we cant seem to get the password to unlock the document again.
Here is what our final settings.xml is looking like.
- Code: Select all
<w:trackRevisions/><w:documentProtection w:salt="765hSrDKb6lC49/43ZYQIw==" w:hash="GQX3oKKv71QhkN5AAR2evA==" w:cryptSpinCount="100000" w:cryptAlgorithmSid="14" w:cryptAlgorithmType="typeAny" w:cryptAlgorithmClass="hash" w:cryptProviderType="rsaAES" w:enforcement="true" w:edit="readOnly"/>
and the docx4j java code creating the protection element
- Code: Select all
// (1.1) lock the entire document and enable tracked changes (revisions) via docx settings.xml
// Create settings part, and init content
DocumentSettingsPart dsp;
try {
dsp = new DocumentSettingsPart();
CTSettings settings = factory.createCTSettings();
settings.setTrackRevisions(new BooleanDefaultTrue());
CTDocProtect dp = factory.createCTDocProtect();
dp.setEdit(STDocProtect.READ_ONLY);
dp.setEnforcement(true);
dp.setCryptProviderType(STCryptProv.RSA_AES);
dp.setCryptAlgorithmClass(STAlgClass.HASH);
dp.setCryptAlgorithmType(STAlgType.TYPE_ANY);
dp.setCryptAlgorithmSid(BigInteger.valueOf(14));
dp.setCryptSpinCount(BigInteger.valueOf(100000));
String hash = "hH19JqFv5Z+txtWMTCKmi1yinjNnO-eiKvnPg19V5rvpjcHK9Lv3JCyCGmZtnrXj5jVVTVyHRSNR5OBTX8egNng=="; //password=xyz
String salt = "qva6VWB5NDLWxfepI9WU4Q==";
try {
byte[] bytesOfMessage = hash.getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] thedigesthash = md.digest(bytesOfMessage);
byte[] bytesOfMessagesalt = salt.getBytes("UTF-8");
MessageDigest mdsalt;
mdsalt = MessageDigest.getInstance("MD5");
byte[] thedigestsalt = mdsalt.digest(bytesOfMessagesalt);
dp.setHash(thedigesthash);
dp.setSalt(thedigestsalt);
} catch (NoSuchAlgorithmException e) {
LOG.error("Could not password protect document - NoSuchAlgorithmException" + e + " -- " );
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
LOG.error("Could not password protect document - UnsupportedEncodingException" + e + " -- " );
e.printStackTrace();
}
dsp.setJaxbElement(settings);
dsp.getContents().setDocumentProtection(dp);
mdp.addTargetPart(dsp);
} catch (InvalidFormatException e1) {
LOG.error(" could not generate document settings, InvalidFormatException something is very wrong.");
e1.printStackTrace();
} catch (Docx4JException e1) {
LOG.error(" could not generate document settings, something is wrong.");
e1.printStackTrace();
}
Something is not right...
Any ideas on how to set the password in plain text?
Looking for a method like this
- Code: Select all
dp.setPlainTextPassword("xyz");