Class SecurityHandler<T_POLICY extends ProtectionPolicy>

  • Type Parameters:
    T_POLICY - the protection policy.
    Direct Known Subclasses:
    PublicKeySecurityHandler, StandardSecurityHandler

    public abstract class SecurityHandler<T_POLICY extends ProtectionPolicy>
    extends java.lang.Object
    A security handler as described in the PDF specifications. A security handler is responsible of documents protection.
    Author:
    Ben Litchfield, Benoit Guillon, Manuel Kasper
    • 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 dictionary
        documentID - 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 dictionary
        documentIDBytes - document id bytes
        decryptionMaterial - Information used to decrypt the document.
        Throws:
        InvalidPasswordException - If the password is incorrect.
        java.io.IOException - If there is an error accessing data.
      • getKeyLength

        public int getKeyLength()
        Getter of the property keyLength.
        Returns:
        Returns the keyLength.
      • setKeyLength

        public void setKeyLength​(int keyLen)
        Setter of the property keyLength.
        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.