Package com.ribs.pdf
Class PDFSecurityHandler
- java.lang.Object
- 
- com.ribs.pdf.PDFSecurityHandler
 
- 
- Direct Known Subclasses:
- PDFEncryptor
 
 public class PDFSecurityHandler extends java.lang.Object
- 
- 
Field SummaryFields Modifier and Type Field Description static intACCESSABILITY_EXTRACTS_ALLOWEDstatic intADD_ANNOTATIONS_ALLOWEDstatic intASSEMBLE_DOCUMENT_ALLOWEDstatic intEXTRACT_TEXT_AND_IMAGES_ALLOWEDstatic intFILL_IN_FORMS_ALLOWEDstatic intMAXIMUM_RESOLUTION_PRINTING_ALLOWEDstatic intMODIFICATIONS_ALLOWEDstatic intPRINTING_ALLOWED
 - 
Constructor SummaryConstructors Constructor Description PDFSecurityHandler()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidarcfour_decrypt(byte[] inout)decrypt using the cached encryption keyvoidauthenticateUserPassword(byte[] uEntry)java.lang.ObjectdecryptDeep(java.lang.Object o)java.lang.ObjectdecryptObject(java.lang.Object o, int objNum, int generationNum)byte[]generateEncryptionKey(byte[] oEntry, java.lang.String password, int keyLength)Uses algorithm 3.2 from pdf spec to generate a key from the filestatic byte[]getBytesForEncryptionEntry(java.util.Map encDict, java.lang.String key)static java.lang.StringgetEncryptionEntryStringForBytes(byte[] buffer)Inverse of abovebyte[]getEncryptionKey(java.util.Map encrypt, java.util.List fileID, java.lang.String pass)Gets the key length and algorithm from the dictionary and creats the keystatic java.lang.ClassgetHandler(java.lang.String name)Convenience method for abovestatic PDFSecurityHandlergetInstance(java.util.Map encryptionDict, java.util.List fileID, java.lang.String pdfversion)Returns an instance of the appropriate PDFSecurityHandler subclass.java.lang.StringgetOwnerPasswordEntry(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.java.lang.StringgetUserPasswordEntry()Returns the string corresponding to the /U entry.byte[]getUserPasswordEntryBytes()voidinit(java.util.Map encryptionDict, java.util.List fileID, java.lang.String pdfversion, java.lang.String apass)Main security handler initialization.static voidmain(java.lang.String[] args)byte[]pad(java.lang.String password)returns a 32 byte array with the characters of the input string, potentially padded with the password padding.static java.lang.ClassregisterHandler(java.lang.Class hclass, java.lang.String key)like a test&set.voidsetEncryptionParameters(byte[] fileID, java.lang.String ownerP, java.lang.String userP, int permissionFlags)Initialization for encryption.voidstartDecrypt(int objNum, int generationNum)
 
- 
- 
- 
Field Detail- 
PRINTING_ALLOWEDpublic static final int PRINTING_ALLOWED - See Also:
- Constant Field Values
 
 - 
MODIFICATIONS_ALLOWEDpublic static final int MODIFICATIONS_ALLOWED - See Also:
- Constant Field Values
 
 - 
EXTRACT_TEXT_AND_IMAGES_ALLOWEDpublic static final int EXTRACT_TEXT_AND_IMAGES_ALLOWED - See Also:
- Constant Field Values
 
 - 
ADD_ANNOTATIONS_ALLOWEDpublic static final int ADD_ANNOTATIONS_ALLOWED - See Also:
- Constant Field Values
 
 - 
FILL_IN_FORMS_ALLOWEDpublic static final int FILL_IN_FORMS_ALLOWED - See Also:
- Constant Field Values
 
 - 
ACCESSABILITY_EXTRACTS_ALLOWEDpublic static final int ACCESSABILITY_EXTRACTS_ALLOWED - See Also:
- Constant Field Values
 
 - 
ASSEMBLE_DOCUMENT_ALLOWEDpublic static final int ASSEMBLE_DOCUMENT_ALLOWED - See Also:
- Constant Field Values
 
 - 
MAXIMUM_RESOLUTION_PRINTING_ALLOWEDpublic static final int MAXIMUM_RESOLUTION_PRINTING_ALLOWED - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
registerHandlerpublic static java.lang.Class registerHandler(java.lang.Class hclass, java.lang.String key)like a test&set. pass null for class to look up, otherwise it sets
 - 
getHandlerpublic static java.lang.Class getHandler(java.lang.String name) Convenience method for above
 - 
getInstancepublic 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.
 - 
initpublic void init(java.util.Map encryptionDict, java.util.List fileID, java.lang.String pdfversion, java.lang.String apass) throws com.ribs.pdf.PDFBadPasswordExceptionMain security handler initialization. Calculates everything necessary to decrypt the pdf objects and performs authorization if necessary.- Throws:
- com.ribs.pdf.PDFBadPasswordException
 
 - 
setEncryptionParameterspublic 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
 - 
getEncryptionKeypublic byte[] getEncryptionKey(java.util.Map encrypt, java.util.List fileID, java.lang.String pass)Gets the key length and algorithm from the dictionary and creats the key
 - 
padpublic byte[] pad(java.lang.String password) returns a 32 byte array with the characters of the input string, potentially padded with the password padding.
 - 
generateEncryptionKeypublic byte[] generateEncryptionKey(byte[] oEntry, java.lang.String password, int keyLength)Uses algorithm 3.2 from pdf spec to generate a key from the file
 - 
authenticateUserPasswordpublic void authenticateUserPassword(byte[] uEntry) throws com.ribs.pdf.PDFBadPasswordException- Throws:
- com.ribs.pdf.PDFBadPasswordException
 
 - 
getUserPasswordEntryBytespublic byte[] getUserPasswordEntryBytes() 
 - 
getBytesForEncryptionEntrypublic static byte[] getBytesForEncryptionEntry(java.util.Map encDict, java.lang.String key)
 - 
getEncryptionEntryStringForBytespublic static java.lang.String getEncryptionEntryStringForBytes(byte[] buffer) Inverse of above
 - 
startDecryptpublic void startDecrypt(int objNum, int generationNum)
 - 
decryptObjectpublic java.lang.Object decryptObject(java.lang.Object o, int objNum, int generationNum)
 - 
decryptDeeppublic java.lang.Object decryptDeep(java.lang.Object o) 
 - 
getOwnerPasswordEntryBytespublic 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.
 - 
getOwnerPasswordEntrypublic java.lang.String getOwnerPasswordEntry(java.lang.String ownerP, java.lang.String userP)Returns the string corresponding to the /O entry.
 - 
getUserPasswordEntrypublic java.lang.String getUserPasswordEntry() Returns the string corresponding to the /U entry. The encryption key is assumed to be calculated already.
 - 
mainpublic static void main(java.lang.String[] args) 
 - 
arcfour_decryptpublic void arcfour_decrypt(byte[] inout) decrypt using the cached encryption key
 
- 
 
-