Package com.pd4ml.pdf.encryption
Class StandardSecurityHandler
- java.lang.Object
-
- com.pd4ml.pdf.encryption.SecurityHandler<StandardProtectionPolicy>
-
- com.pd4ml.pdf.encryption.StandardSecurityHandler
-
public final class StandardSecurityHandler extends SecurityHandler<StandardProtectionPolicy>
The standard security handler. This security handler protects document with password.- Author:
- Ben Litchfield, Benoit Guillon, Manuel Kasper
- See Also:
to see how to protect document with this security handler.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFILTERType of security handler.static java.lang.Class<?>PROTECTION_POLICY_CLASSProtection policy class for this handler.
-
Constructor Summary
Constructors Constructor Description StandardSecurityHandler()Constructor.StandardSecurityHandler(StandardProtectionPolicy standardProtectionPolicy)Constructor used for encryption.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]computeEncryptedKey(byte[] password, byte[] o, byte[] u, byte[] oe, byte[] ue, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata, boolean isOwnerPassword)Compute the encryption key.byte[]computeOwnerPassword(byte[] ownerPassword, byte[] userPassword, int encRevision, int length)Compute the owner entry in the encryption dictionary.byte[]computeUserPassword(byte[] password, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata)This will compute the user password hash.byte[]getUserPassword(byte[] ownerPassword, byte[] owner, int encRevision, int length)Get the user password based on the owner password.booleanisOwnerPassword(byte[] ownerPassword, byte[] user, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata)Check for owner password.booleanisOwnerPassword(java.lang.String password, byte[] user, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata)Check for owner password.booleanisUserPassword(byte[] password, byte[] user, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata)Check if a plaintext password is the user password.booleanisUserPassword(java.lang.String password, byte[] user, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata)Check if a plaintext password is the user password.voidprepareDocumentForEncryption(PDEncryption encryptionDictionary, byte[] documentID)Prepare document for encryption.voidprepareForDecryption(PDEncryption encryption, byte[] documentIDBytes, DecryptionMaterial decryptionMaterial)Prepares everything to decrypt the document.-
Methods inherited from class com.pd4ml.pdf.encryption.SecurityHandler
decryptBuffer, getCurrentAccessPermission, getEncryptionKey, getKeyLength, hasProtectionPolicy, isAES, isDecryptMetadata, setAES, setCurrentAccessPermission, setCustomSecureRandom, setEncryptionKey, setKeyLength, setParams
-
-
-
-
Field Detail
-
FILTER
public static final java.lang.String FILTER
Type of security handler.- See Also:
- Constant Field Values
-
PROTECTION_POLICY_CLASS
public static final java.lang.Class<?> PROTECTION_POLICY_CLASS
Protection policy class for this handler.
-
-
Constructor Detail
-
StandardSecurityHandler
public StandardSecurityHandler()
Constructor.
-
StandardSecurityHandler
public StandardSecurityHandler(StandardProtectionPolicy standardProtectionPolicy)
Constructor used for encryption.- Parameters:
standardProtectionPolicy- The protection policy.
-
-
Method Detail
-
prepareForDecryption
public void prepareForDecryption(PDEncryption encryption, byte[] documentIDBytes, DecryptionMaterial decryptionMaterial) throws java.io.IOException
Prepares everything to decrypt the document. Only if decryption of single objects is needed this should be called.- Specified by:
prepareForDecryptionin classSecurityHandler<StandardProtectionPolicy>- Parameters:
encryption- encryption dictionarydocumentIDBytes- document iddecryptionMaterial- Information used to decrypt the document.- Throws:
InvalidPasswordException- If the password is incorrect.java.io.IOException- If there is an error accessing data.
-
prepareDocumentForEncryption
public void prepareDocumentForEncryption(PDEncryption encryptionDictionary, byte[] documentID) throws java.io.IOException
Prepare document for encryption.- Specified by:
prepareDocumentForEncryptionin classSecurityHandler<StandardProtectionPolicy>- Parameters:
encryptionDictionary- encryption dictionarydocumentID- document ID bytes- Throws:
java.io.IOException- If there is an error accessing data.
-
isOwnerPassword
public boolean isOwnerPassword(byte[] ownerPassword, byte[] user, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata) throws java.io.IOExceptionCheck for owner password.- Parameters:
ownerPassword- The owner password.user- The u entry of the encryption dictionary.owner- The o entry of the encryption dictionary.permissions- The set of permissions on the document.id- The document id.encRevision- The encryption algorithm revision.keyLengthInBytes- The encryption key length in bytes.encryptMetadata- The encryption metadata- Returns:
- True If the ownerPassword param is the owner password.
- Throws:
java.io.IOException- If there is an error accessing data.
-
getUserPassword
public byte[] getUserPassword(byte[] ownerPassword, byte[] owner, int encRevision, int length) throws java.io.IOExceptionGet the user password based on the owner password.- Parameters:
ownerPassword- The plaintext owner password.owner- The o entry of the encryption dictionary.encRevision- The encryption revision number.length- The key length.- Returns:
- The u entry of the encryption dictionary.
- Throws:
java.io.IOException- If there is an error accessing data while generating the user password.
-
computeEncryptedKey
public byte[] computeEncryptedKey(byte[] password, byte[] o, byte[] u, byte[] oe, byte[] ue, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata, boolean isOwnerPassword) throws java.io.IOExceptionCompute the encryption key.- Parameters:
password- The password to compute the encrypted key.o- The O entry of the encryption dictionary.u- The U entry of the encryption dictionary.oe- The OE entry of the encryption dictionary.ue- The UE entry of the encryption dictionary.permissions- The permissions for the document.id- The document id.encRevision- The revision of the encryption algorithm.keyLengthInBytes- The length of the encryption key in bytes.encryptMetadata- The encryption metadataisOwnerPassword- whether the password given is the owner password (for revision 6)- Returns:
- The encrypted key bytes.
- Throws:
java.io.IOException- If there is an error with encryption.
-
computeUserPassword
public byte[] computeUserPassword(byte[] password, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata) throws java.io.IOExceptionThis will compute the user password hash.- Parameters:
password- The plain text password.owner- The owner password hash.permissions- The document permissions.id- The document id.encRevision- The revision of the encryption.keyLengthInBytes- The length of the encryption key in bytes.encryptMetadata- The encryption metadata- Returns:
- The user password.
- Throws:
java.io.IOException- if the password could not be computed
-
computeOwnerPassword
public byte[] computeOwnerPassword(byte[] ownerPassword, byte[] userPassword, int encRevision, int length) throws java.io.IOExceptionCompute the owner entry in the encryption dictionary.- Parameters:
ownerPassword- The plaintext owner password.userPassword- The plaintext user password.encRevision- The revision number of the encryption algorithm.length- The length of the encryption key.- Returns:
- The o entry of the encryption dictionary.
- Throws:
java.io.IOException- if the owner password could not be computed
-
isUserPassword
public boolean isUserPassword(byte[] password, byte[] user, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata) throws java.io.IOExceptionCheck if a plaintext password is the user password.- Parameters:
password- The plaintext password.user- The u entry of the encryption dictionary.owner- The o entry of the encryption dictionary.permissions- The permissions set in the PDF.id- The document id used for encryption.encRevision- The revision of the encryption algorithm.keyLengthInBytes- The length of the encryption key in bytes.encryptMetadata- The encryption metadata.- Returns:
- true If the plaintext password is the user password.
- Throws:
java.io.IOException- If there is an error accessing data.
-
isUserPassword
public boolean isUserPassword(java.lang.String password, byte[] user, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata) throws java.io.IOExceptionCheck if a plaintext password is the user password.- Parameters:
password- The plaintext password.user- The u entry of the encryption dictionary.owner- The o entry of the encryption dictionary.permissions- The permissions set in the PDF.id- The document id used for encryption.encRevision- The revision of the encryption algorithm.keyLengthInBytes- The length of the encryption key in bytes.encryptMetadata- The encryption metadata- Returns:
- true If the plaintext password is the user password.
- Throws:
java.io.IOException- If there is an error accessing data.
-
isOwnerPassword
public boolean isOwnerPassword(java.lang.String password, byte[] user, byte[] owner, int permissions, byte[] id, int encRevision, int keyLengthInBytes, boolean encryptMetadata) throws java.io.IOExceptionCheck for owner password.- Parameters:
password- The owner password.user- The u entry of the encryption dictionary.owner- The o entry of the encryption dictionary.permissions- The set of permissions on the document.id- The document id.encRevision- The encryption algorithm revision.keyLengthInBytes- The encryption key length in bytes.encryptMetadata- The encryption metadata- Returns:
- True If the ownerPassword param is the owner password.
- Throws:
java.io.IOException- If there is an error accessing data.
-
-