/** * Constructor used for encryption. * * @param p The protection policy. */ public StandardSecurityHandler(StandardProtectionPolicy p) { policy = p; keyLength = policy.getEncryptionKeyLength(); }
/** * Computes the revision version of the StandardSecurityHandler to * use regarding the version number and the permissions bits set. * See PDF Spec 1.6 p98 * * @param version The version number. * * @return The computed revision number. */ private int computeRevisionNumber(int version) { if(version < 2 && !policy.getPermissions().hasAnyRevision3PermissionSet()) { return 2; } if (version == 5) { // note about revision 5: "Shall not be used. This value was used by a deprecated Adobe extension." return 6; } if (version == 4) { return 4; } if ( version == 2 || version == 3 || policy.getPermissions().hasAnyRevision3PermissionSet()) { return 3; } return 4; }
/** * Computes the version number of the StandardSecurityHandler based on the encryption key * length. * See PDF Spec 1.6 p 93 and PDF 1.7 AEL3 * * @return The computed version number. */ private int computeVersionNumber() { if(keyLength == 40) { return DEFAULT_VERSION; } else if (keyLength == 128 && policy.isPreferAES()) { return 4; } else if (keyLength == 256) { return 5; } return 2; }
encryptionDictionary.setLength(keyLength); String ownerPassword = policy.getOwnerPassword(); String userPassword = policy.getUserPassword(); if( ownerPassword == null ) int permissionInt = policy.getPermissions().getPermissionBytes();
new StandardProtectionPolicy(ownerPassword, userPassword, ap); spp.setEncryptionKeyLength(keyLength); document.protect(spp);
// owner password to open the file with all permissions // user password to open the file but with restricted permissions, can be empty StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPass, userPass, access); spp.setEncryptionKeyLength(128); doc.protect(spp);
private PDDocument getDocument(RandomAccessRead source) throws IOException, BleachException { PDDocument doc; for (String pwd : COMMON_PASSWORDS) { ScratchFile scratchFile = new ScratchFile(MEMORY_USAGE_SETTING); doc = testPassword(scratchFile, source, pwd); if (doc != null) { LOGGER.debug("Password was guessed: '{}'", pwd); doc.protect(new StandardProtectionPolicy(pwd, pwd, doc.getCurrentAccessPermission())); return doc; } scratchFile.close(); } // @TODO: fetch password from config? throw new BleachException("PDF is protected with an unknown password"); }
encryptionDictionary.setLength(keyLength); String ownerPassword = policy.getOwnerPassword(); String userPassword = policy.getUserPassword(); if( ownerPassword == null ) int permissionInt = policy.getPermissions().getPermissionBytes();
new StandardProtectionPolicy(ownerPassword, userPassword, ap); spp.setEncryptionKeyLength(keyLength); document.protect(spp);
encryptionDictionary.setLength(keyLength); String ownerPassword = policy.getOwnerPassword(); String userPassword = policy.getUserPassword(); if( ownerPassword == null ) int permissionInt = policy.getPermissions().getPermissionBytes();
StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPwd, userPwd, inPerm); spp.setEncryptionKeyLength(keyLength); pdfDoc = PDDocument.load(pdfBlob.getFile()); pdfDoc.protect(spp);
/** * Constructor used for encryption. * * @param p The protection policy. */ public StandardSecurityHandler(StandardProtectionPolicy p) { policy = p; keyLength = policy.getEncryptionKeyLength(); }
/** * Computes the version number of the StandardSecurityHandler * based on the encryption key length. * See PDF Spec 1.6 p 93 and PDF 1.7 AEL3 * * @return The computed version number. */ private int computeVersionNumber() { if(keyLength == 40) { return DEFAULT_VERSION; } else if (keyLength == 128 && policy.isPreferAES()) { return 4; } else if (keyLength == 256) { return 5; } return 2; }
/** * Computes the revision version of the StandardSecurityHandler to * use regarding the version number and the permissions bits set. * See PDF Spec 1.6 p98 * * @param version The version number. * * @return The computed revision number. */ private int computeRevisionNumber(int version) { if(version < 2 && !policy.getPermissions().hasAnyRevision3PermissionSet()) { return 2; } if (version == 5) { // note about revision 5: "Shall not be used. This value was used by a deprecated Adobe extension." return 6; } if (version == 4) { return 4; } if ( version == 2 || version == 3 || policy.getPermissions().hasAnyRevision3PermissionSet()) { return 3; } return 4; }
/** * Constructor used for encryption. * * @param p The protection policy. */ public StandardSecurityHandler(StandardProtectionPolicy p) { policy = p; keyLength = policy.getEncryptionKeyLength(); }
/** * Computes the version number of the StandardSecurityHandler * regarding the encryption key length. * See PDF Spec 1.6 p 93 and PDF 1.7 AEL3 * * @return The computed version number. */ private int computeVersionNumber() { if(keyLength == 40) { return DEFAULT_VERSION; } else if (keyLength == 128 && policy.isPreferAES()) { return 4; } else if (keyLength == 256) { return 5; } return 2; }
/** * Computes the revision version of the StandardSecurityHandler to * use regarding the version number and the permissions bits set. * See PDF Spec 1.6 p98 * * @param version The version number. * * @return The computed revision number. */ private int computeRevisionNumber(int version) { if(version < 2 && !policy.getPermissions().hasAnyRevision3PermissionSet()) { return 2; } if (version == 5) { // note about revision 5: "Shall not be used. This value was used by a deprecated Adobe extension." return 6; } if (version == 4) { return 4; } if ( version == 2 || version == 3 || policy.getPermissions().hasAnyRevision3PermissionSet()) { return 3; } return 4; }