Class PDFSecurityHandler
- java.lang.Object
-
- com.inductiveautomation.rm.pdf.reader.PDFSecurityHandler
-
- Direct Known Subclasses:
PDFEncryptor
public class PDFSecurityHandler extends java.lang.Object
Implementation of the Adobe Standard security handler using the Sun security extensions for md5 & rc4.
-
-
Field Summary
Fields Modifier and Type Field Description static int
ACCESSABILITY_EXTRACTS_ALLOWED
static int
ADD_ANNOTATIONS_ALLOWED
static int
ASSEMBLE_DOCUMENT_ALLOWED
static int
EXTRACT_TEXT_AND_IMAGES_ALLOWED
static int
FILL_IN_FORMS_ALLOWED
static int
MAXIMUM_RESOLUTION_PRINTING_ALLOWED
static int
MODIFICATIONS_ALLOWED
static int
PRINTING_ALLOWED
-
Constructor Summary
Constructors Constructor Description PDFSecurityHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
arcfour_decrypt(byte[] inout)
decrypt using the cached encryption key.java.lang.Object
decryptDeep(java.lang.Object o)
Decrypt.java.lang.Object
decryptObject(java.lang.Object o, int objNum, int generationNum)
Decrypt strings & streams using the algorithm from the encryption dictionary.static byte[]
getBytesForEncryptionEntry(java.util.Map encDict, java.lang.String key)
Similar to, but not exactly like normal string escape.byte[]
getEncryptionKey(byte[] oEntry, java.lang.String uPass, int keyLen)
Uses algorithm 3.2 from pdf spec to generate a key from the file.byte[]
getEncryptionKey(java.util.Map encrypt, java.util.List fileID, java.lang.String uPass)
Gets the key length and algorithm from the dictionary and creats the keystatic PDFSecurityHandler
getInstance(java.util.Map encryptionDict, java.util.List fileID, java.lang.String pdfversion)
Returns an instance of the appropriate PDFSecurityHandler subclass.java.lang.String
getOwnerPasswordEntry(java.lang.String ownerP, java.lang.String userP)
Returns the string corresponding to the /O entry.byte[]
getOwnerPasswordEntryBytes(java.lang.String ownerP, java.lang.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.static java.lang.String
getPDFStringForBytes(byte[] buf)
Inverse of abovejava.lang.String
getUserPasswordEntry()
Returns the string corresponding to the /U entry.byte[]
getUserPasswordEntryBytes()
Return User password entry bytes.void
init(java.util.Map encryptDict, java.util.List fileID, java.lang.String pdfversion, java.lang.String uPass)
Main security handler initialization.static void
main(java.lang.String[] args)
Testing.void
setEncryptionParameters(byte[] fileID, java.lang.String ownerP, java.lang.String userP, int permissionFlags)
Initialization for encryption.void
startDecrypt(int objNum, int generationNum)
Create encryption key for given object numbers and cache it for recursive invocations of decryptDeep().
-
-
-
Field Detail
-
PRINTING_ALLOWED
public static final int PRINTING_ALLOWED
- See Also:
- Constant Field Values
-
MODIFICATIONS_ALLOWED
public static final int MODIFICATIONS_ALLOWED
- See Also:
- Constant Field Values
-
EXTRACT_TEXT_AND_IMAGES_ALLOWED
public static final int EXTRACT_TEXT_AND_IMAGES_ALLOWED
- See Also:
- Constant Field Values
-
ADD_ANNOTATIONS_ALLOWED
public static final int ADD_ANNOTATIONS_ALLOWED
- See Also:
- Constant Field Values
-
FILL_IN_FORMS_ALLOWED
public static final int FILL_IN_FORMS_ALLOWED
- See Also:
- Constant Field Values
-
ACCESSABILITY_EXTRACTS_ALLOWED
public static final int ACCESSABILITY_EXTRACTS_ALLOWED
- See Also:
- Constant Field Values
-
ASSEMBLE_DOCUMENT_ALLOWED
public static final int ASSEMBLE_DOCUMENT_ALLOWED
- See Also:
- Constant Field Values
-
MAXIMUM_RESOLUTION_PRINTING_ALLOWED
public static final int MAXIMUM_RESOLUTION_PRINTING_ALLOWED
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static PDFSecurityHandler getInstance(java.util.Map encryptionDict, java.util.List fileID, java.lang.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(java.util.Map encryptDict, java.util.List fileID, java.lang.String pdfversion, java.lang.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, java.lang.String ownerP, java.lang.String userP, int permissionFlags)
Initialization for encryption. Sets parameters to revision=3, 128 bit keys.
-
getEncryptionKey
public byte[] getEncryptionKey(java.util.Map encrypt, java.util.List fileID, java.lang.String uPass)
Gets the key length and algorithm from the dictionary and creats the key
-
getEncryptionKey
public byte[] getEncryptionKey(byte[] oEntry, java.lang.String uPass, int keyLen)
Uses algorithm 3.2 from pdf spec to generate a key from the file.
-
getUserPasswordEntry
public java.lang.String getUserPasswordEntry()
Returns the string corresponding to the /U entry. The encryption key is assumed to be calculated already.
-
getOwnerPasswordEntry
public java.lang.String getOwnerPasswordEntry(java.lang.String ownerP, java.lang.String userP)
Returns the string corresponding to the /O entry.
-
getUserPasswordEntryBytes
public byte[] getUserPasswordEntryBytes()
Return User password entry bytes.
-
getOwnerPasswordEntryBytes
public byte[] getOwnerPasswordEntryBytes(java.lang.String ownerP, java.lang.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 java.lang.Object decryptObject(java.lang.Object o, int objNum, int generationNum)
Decrypt strings & streams using the algorithm from the encryption dictionary.
-
decryptDeep
public java.lang.Object decryptDeep(java.lang.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(java.util.Map encDict, java.lang.String key)
Similar to, but not exactly like normal string escape.
-
getPDFStringForBytes
public static java.lang.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(java.lang.String[] args) throws java.io.UnsupportedEncodingException, java.io.IOException
Testing.- Throws:
java.io.UnsupportedEncodingException
java.io.IOException
-
-