Class SecurityHandler

java.lang.Object
org.sejda.sambox.pdmodel.encryption.SecurityHandler
Direct Known Subclasses:
PublicKeySecurityHandler, StandardSecurityHandler

public abstract class SecurityHandler extends 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
  • Field Details

    • keyLength

      protected short keyLength
      The length of the secret key used to encrypt the document.
  • Constructor Details

    • SecurityHandler

      public SecurityHandler()
  • Method Details

    • setDecryptMetadata

      protected void setDecryptMetadata(boolean decryptMetadata)
      Set wether to decrypt meta data.
      Parameters:
      decryptMetadata - true if meta data has to be decrypted.
    • isDecryptMetadata

      public boolean isDecryptMetadata()
      Returns:
      True if meta data has to be decrypted.
    • setStringFilterName

      protected void setStringFilterName(COSName stringFilterName)
      Set the string filter name.
      Parameters:
      stringFilterName - the string filter name.
    • setStreamFilterName

      protected void setStreamFilterName(COSName streamFilterName)
      Set the stream filter name.
      Parameters:
      streamFilterName - the stream filter name.
    • prepareForDecryption

      public abstract void prepareForDecryption(PDEncryption encryption, COSArray documentIDArray, DecryptionMaterial decryptionMaterial) throws IOException
      Prepares everything to decrypt the document.
      Parameters:
      encryption - encryption dictionary, can be retrieved via PDDocument.getEncryption()
      documentIDArray - document id which is returned via COSDocument.getDocumentID()
      decryptionMaterial - Information used to decrypt the document.
      Throws:
      IOException - If there is an error accessing data.
    • decryptDataRC4

      protected void decryptDataRC4(byte[] finalKey, InputStream input, OutputStream output) throws IOException
      Encrypt or decrypt data with RC4.
      Parameters:
      finalKey - The final key obtained with via calcFinalKey(long, long).
      input - The data to encrypt.
      output - The output to write the encrypted data to.
      Throws:
      IOException - If there is an error reading the data.
    • decryptDataRC4

      protected void decryptDataRC4(byte[] finalKey, byte[] input, OutputStream output) throws IOException
      Encrypt or decrypt data with RC4.
      Parameters:
      finalKey - The final key obtained with via calcFinalKey(long, long).
      input - The data to encrypt.
      output - The output to write the encrypted data to.
      Throws:
      IOException - If there is an error reading the data.
    • decrypt

      public void decrypt(COSBase obj, long objNum, long genNum) throws IOException
      This will dispatch to the correct method.
      Parameters:
      obj - The object to decrypt.
      objNum - The object number.
      genNum - The object generation Number.
      Throws:
      IOException - If there is an error getting the stream data.
    • decryptStream

      public void decryptStream(COSStream stream, long objNum, long genNum) throws IOException
      This will decrypt a stream.
      Parameters:
      stream - The stream to decrypt.
      objNum - The object number.
      genNum - The object generation number.
      Throws:
      IOException - If there is an error getting the stream data.
    • getKeyLength

      public int getKeyLength()
      Returns:
      key length in bits
    • setKeyLength

      public void setKeyLength(int keyLen)
    • setCurrentAccessPermission

      public void setCurrentAccessPermission(AccessPermission currentAccessPermission)
      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
    • getEncryptionKey

      public byte[] getEncryptionKey()
    • setEncryptionKey

      protected void setEncryptionKey(byte[] encryptionKey)