I try to protect a Word document to READ Only mode using the docx4java API. Using the following code;
CTDocProtect cdtP = new CTDocProtect();
cdtP.setEnforcement(Boolean.TRUE);
cdtP.setEdit(STDocProtect.READ_ONLY);
// Set password for protection
String password = "aaaa" ;
Random rnd = new SecureRandom();
int spins = 100000 ;
int keylength = 256 ;
byte[] salt = new byte[16];
rnd.nextBytes(salt);
byte[] hash = new byte[0] ;
hash = password.getBytes() ;
cdtP.setCryptProviderType(STCryptProv.RSA_FULL);
cdtP.setCryptAlgorithmClass(STAlgClass.HASH);
cdtP.setCryptAlgorithmType(STAlgType.TYPE_ANY);
cdtP.setCryptAlgorithmSid(BigInteger.valueOf(4));
cdtP.setCryptSpinCount(BigInteger.valueOf(spins));
cdtP.setHash(hash);
cdtP.setSalt(salt); ...