Class PDFSecurityHandler

java.lang.Object
com.inductiveautomation.rm.pdf.reader.PDFSecurityHandler
Direct Known Subclasses:
PDFEncryptor

public class PDFSecurityHandler extends Object
Implementation of the Adobe Standard security handler using the Sun security extensions for md5 & rc4.
  • Field Details

    • PRINTING_ALLOWED

      public static final int PRINTING_ALLOWED
      See Also:
    • MODIFICATIONS_ALLOWED

      public static final int MODIFICATIONS_ALLOWED
      See Also:
    • EXTRACT_TEXT_AND_IMAGES_ALLOWED

      public static final int EXTRACT_TEXT_AND_IMAGES_ALLOWED
      See Also:
    • ADD_ANNOTATIONS_ALLOWED

      public static final int ADD_ANNOTATIONS_ALLOWED
      See Also:
    • FILL_IN_FORMS_ALLOWED

      public static final int FILL_IN_FORMS_ALLOWED
      See Also:
    • ACCESSABILITY_EXTRACTS_ALLOWED

      public static final int ACCESSABILITY_EXTRACTS_ALLOWED
      See Also:
    • ASSEMBLE_DOCUMENT_ALLOWED

      public static final int ASSEMBLE_DOCUMENT_ALLOWED
      See Also:
    • MAXIMUM_RESOLUTION_PRINTING_ALLOWED

      public static final int MAXIMUM_RESOLUTION_PRINTING_ALLOWED
      See Also:
  • Constructor Details

    • PDFSecurityHandler

      public PDFSecurityHandler()
  • Method Details

    • getInstance

      public static PDFSecurityHandler getInstance(Map encryptionDict, List fileID, String pdfversion)
      Returns an instance of the appropriate PDFSecurityHandler subclass. Since any number of different security handlers can be used in pdf, callers should use this method rather than instantiating a handler directly. This also does authentication with the handler, possibly raising a panel to ask for passwords, keys, etc.
    • init

      public void init(Map encryptDict, List fileID, String pdfversion, String uPass) throws com.inductiveautomation.rm.pdf.reader.PDFSecurityHandler.PDFBadPasswordException
      Main security handler initialization. Calculates everything necessary to decrypt the pdf objects and performs authorization if necessary.
      Throws:
      com.inductiveautomation.rm.pdf.reader.PDFSecurityHandler.PDFBadPasswordException
    • setEncryptionParameters

      public void setEncryptionParameters(byte[] fileID, String ownerP, String userP, int permissionFlags)
      Initialization for encryption. Sets parameters to revision=3, 128 bit keys.
    • getEncryptionKey

      public byte[] getEncryptionKey(Map encrypt, List fileID, String uPass)
      Gets the key length and algorithm from the dictionary and creats the key
    • getEncryptionKey

      public byte[] getEncryptionKey(byte[] oEntry, String uPass, int keyLen)
      Uses algorithm 3.2 from pdf spec to generate a key from the file.
    • getUserPasswordEntry

      public String getUserPasswordEntry()
      Returns the string corresponding to the /U entry. The encryption key is assumed to be calculated already.
    • getOwnerPasswordEntry

      public String getOwnerPasswordEntry(String ownerP, String userP)
      Returns the string corresponding to the /O entry.
    • getUserPasswordEntryBytes

      public byte[] getUserPasswordEntryBytes()
      Return User password entry bytes.
    • getOwnerPasswordEntryBytes

      public byte[] getOwnerPasswordEntryBytes(String ownerP, String userP)
      For encryption - generate a /O encryption entry for an encryption dictionary (from Algorithm 3.3 of the spec) This routine uses Revision 3 of the algorithm and 128 bit keys.
    • decryptObject

      public Object decryptObject(Object o, int objNum, int generationNum)
      Decrypt strings & streams using the algorithm from the encryption dictionary.
    • decryptDeep

      public Object decryptDeep(Object o)
      Decrypt.
    • startDecrypt

      public void startDecrypt(int objNum, int generationNum)
      Create encryption key for given object numbers and cache it for recursive invocations of decryptDeep().
    • getBytesForEncryptionEntry

      public static byte[] getBytesForEncryptionEntry(Map encDict, String key)
      Similar to, but not exactly like normal string escape.
    • getPDFStringForBytes

      public static String getPDFStringForBytes(byte[] buf)
      Inverse of above
    • arcfour_decrypt

      public void arcfour_decrypt(byte[] inout)
      decrypt using the cached encryption key.
    • main

      public static void main(String[] args) throws IOException
      Testing.
      Throws:
      IOException