Package com.pd4ml.pdf.encryption
Class SecurityHandler<T_POLICY extends ProtectionPolicy>
- java.lang.Object
-
- com.pd4ml.pdf.encryption.SecurityHandler<T_POLICY>
-
- Type Parameters:
T_POLICY- the protection policy.
- Direct Known Subclasses:
PublicKeySecurityHandler,StandardSecurityHandler
public abstract class SecurityHandler<T_POLICY extends ProtectionPolicy> extends java.lang.ObjectA security handler as described in the PDF specifications. A security handler is responsible of documents protection.- Author:
- Ben Litchfield, Benoit Guillon, Manuel Kasper
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description byte[]decryptBuffer(long objectNumber, long genNumber, byte[] bytes)AccessPermissiongetCurrentAccessPermission()Returns the access permissions that were computed during document decryption.byte[]getEncryptionKey()Returns the current encryption key data.intgetKeyLength()Getter of the propertykeyLength.booleanhasProtectionPolicy()Returns whether a protection policy has been set.booleanisAES()True if AES is used for encryption and decryption.booleanisDecryptMetadata()Returns true if meta data is to be decrypted.abstract voidprepareDocumentForEncryption(PDEncryption encryptionDictionary, byte[] documentID)Prepare the document for encryption.abstract voidprepareForDecryption(PDEncryption encryption, byte[] documentIDBytes, DecryptionMaterial decryptionMaterial)Prepares everything to decrypt the document.voidsetAES(boolean aesValue)Set to true if AES for encryption and decryption should be used.voidsetCurrentAccessPermission(AccessPermission currentAccessPermission)Sets the access permissions.voidsetCustomSecureRandom(java.security.SecureRandom customSecureRandom)Set the custom SecureRandom.voidsetEncryptionKey(byte[] encryptionKey)Sets the current encryption key data.voidsetKeyLength(int keyLen)Setter of the propertykeyLength.voidsetParams(boolean encrypt, T_POLICY protectionPolicy, PDEncryption encryptionDict, byte[] fingerprint, java.lang.String password)
-
-
-
Method Detail
-
setParams
public void setParams(boolean encrypt, T_POLICY protectionPolicy, PDEncryption encryptionDict, byte[] fingerprint, java.lang.String password) throws java.io.IOException- Throws:
java.io.IOException
-
isDecryptMetadata
public boolean isDecryptMetadata()
Returns true if meta data is to be decrypted.- Returns:
- True if meta data has to be decrypted.
-
setCustomSecureRandom
public void setCustomSecureRandom(java.security.SecureRandom customSecureRandom)
Set the custom SecureRandom.- Parameters:
customSecureRandom- the custom SecureRandom for AES encryption
-
prepareDocumentForEncryption
public abstract void prepareDocumentForEncryption(PDEncryption encryptionDictionary, byte[] documentID) throws java.io.IOException
Prepare the document for encryption.- Parameters:
encryptionDictionary- encryption dictionarydocumentID- document ID bytes- Throws:
java.io.IOException- If there is an error with the document.
-
prepareForDecryption
public abstract void prepareForDecryption(PDEncryption encryption, byte[] documentIDBytes, DecryptionMaterial decryptionMaterial) throws java.io.IOException
Prepares everything to decrypt the document.- Parameters:
encryption- encryption dictionarydocumentIDBytes- document id bytesdecryptionMaterial- Information used to decrypt the document.- Throws:
InvalidPasswordException- If the password is incorrect.java.io.IOException- If there is an error accessing data.
-
decryptBuffer
public byte[] decryptBuffer(long objectNumber, long genNumber, byte[] bytes) throws CryptographyException, java.io.IOException- Throws:
CryptographyExceptionjava.io.IOException
-
getKeyLength
public int getKeyLength()
Getter of the propertykeyLength.- Returns:
- Returns the keyLength.
-
setKeyLength
public void setKeyLength(int keyLen)
Setter of the propertykeyLength.- Parameters:
keyLen- The keyLength to set.
-
setCurrentAccessPermission
public void setCurrentAccessPermission(AccessPermission currentAccessPermission)
Sets the access permissions.- Parameters:
currentAccessPermission- The access permissions to be set.
-
getCurrentAccessPermission
public AccessPermission getCurrentAccessPermission()
Returns the access permissions that were computed during document decryption. The returned object is in read only mode.- Returns:
- the access permissions or null if the document was not decrypted.
-
isAES
public boolean isAES()
True if AES is used for encryption and decryption.- Returns:
- true if AEs is used
-
setAES
public void setAES(boolean aesValue)
Set to true if AES for encryption and decryption should be used.- Parameters:
aesValue- if true AES will be used
-
hasProtectionPolicy
public boolean hasProtectionPolicy()
Returns whether a protection policy has been set.- Returns:
- true if a protection policy has been set.
-
getEncryptionKey
public byte[] getEncryptionKey()
Returns the current encryption key data.- Returns:
- The current encryption key data.
-
setEncryptionKey
public void setEncryptionKey(byte[] encryptionKey)
Sets the current encryption key data.- Parameters:
encryptionKey- The encryption key data to set.
-
-