|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.EncryptionHandler
org.faceless.pdf2.StandardEncryptionHandler
public class StandardEncryptionHandler
Represents the standard Acrobat encryption algorithm, both 40-bit and 128-bit variants.
The only methods the end-user need worry about are setUserPassword(java.lang.String)
, setOwnerPassword(java.lang.String)
,
setAcrobat3Level(boolean, boolean, boolean, boolean)
and setAcrobat5Level(int, int, int)
- all the other methods are used by
the encryption process itself.
StandardEncryptionHandler encrypt = new StandardEncryptionHandler(); encrypt.setAcrobat3Level(false, true, true, true); pdf.setEncryptionHandler(encrypt);For reading a document with a password, the
PDFReader
class has a convenience method
whereby a password can be passed in as a String
to decrypt. However, if you wanted to
pass in an EncryptionHandler
that would have the same result, you could do this:
StandardEncryptionHandler encrypt = new StandardEncryptionHandler(); encrypt.setUserPassword("secret"); PDFReader reader = new PDFReader(inputstream, encrypt); inputstream.close(); PDF pdf = new PDF(reader);
PDF.setEncryptionHandler(org.faceless.pdf2.EncryptionHandler)
,
PDFReader.PDFReader(InputStream,EncryptionHandler)
Field Summary | |
---|---|
static int |
CHANGE_ALL
Parameter to setAcrobat5Level(int, int, int) to allow the document to be modified in any way |
static int |
CHANGE_ANNOTATIONS
Parameter to setAcrobat5Level(int, int, int) to allow form fields and annotations to be added
or modified |
static int |
CHANGE_FORMS
Parameter to setAcrobat5Level(int, int, int) to allow only form fields to be completed |
static int |
CHANGE_LAYOUT
Parameter to setAcrobat5Level(int, int, int) to allow only pages to be inserted, deleted, rotated
and reordered |
static int |
CHANGE_NONE
Parameter to setAcrobat5Level(int, int, int) to disallow all changes to the document |
static int |
EXTRACT_ACCESSIBILITY
Parameter to setAcrobat5Level(int, int, int) to allow the limited copying of images and text
for the purposes of accessibility for disabled users |
static int |
EXTRACT_ALL
Parameter to setAcrobat5Level(int, int, int) to allow copying of images and text from the
document. |
static int |
EXTRACT_NONE
Parameter to setAcrobat5Level(int, int, int) to prevent any copying of images of text |
static int |
PRINT_HIGHRES
Parameter to setAcrobat5Level(int, int, int) to allow full print access |
static int |
PRINT_LOWRES
Parameter to setAcrobat5Level(int, int, int) to limit printing to lo-res (theoretically about 150dpi) |
static int |
PRINT_NONE
Parameter to setAcrobat5Level(int, int, int) to prevent printing altogether |
Constructor Summary | |
---|---|
StandardEncryptionHandler()
Create a new StandardEncryptionHandler for encryption or decryption of documents. |
Method Summary | |
---|---|
Object |
clone()
|
boolean |
equals(Object o)
|
void |
finishedDecrypt()
This method is called after the PDF has been read. |
void |
finishedEncrypt()
This method is called after the PDF has been written. |
int |
getChange()
Return the value of the "Change" flags |
int |
getDecryptedStreamLength(int len)
Return the length that an encrypted stream o the specified length would be after decryption. |
InputStream |
getDecryptionStream(InputStream in,
int num,
int gen)
Return a FilterInputStream that will decrypt anything read
from it. |
String |
getDescription()
Return a textual description of the algorithm used |
int |
getEncryptedStreamLength(int len)
Return the length that a stream of the specified length would be after encryption. |
OutputStream |
getEncryptionStream(OutputStream out,
int num,
int gen)
Return a FilterOutputStream that will encrypt anything written
to it. |
int |
getExtract()
Return the value of the "Extract" flags |
String |
getFilterName()
Return the name of the "Filter" field in the Encryption dictionary. |
int |
getPrint()
Return the value of the "Print" flags |
String |
getSubFilterName()
Return the name of the "Subfilter" field in the Encryption dictionary. |
int |
getVersion()
Return the version of the encryption algorithm used. |
int |
hashCode()
|
boolean |
hasRight(String right)
Returns true if the EncryptionHandler wil grant the specified right to the PDF library. |
boolean |
isEmbeddedFileEncrypted()
This method returns true if Embedded Files in the document should be stored encrypted. |
boolean |
isMetadataEncrypted()
This method returns true if XMP MetaData should be stored encrypted, or false otherwise. |
boolean |
isOwnerPasswordKnown()
Return true if the Owner password was used to open this PDF, false if the User password was used. |
boolean |
isRequired()
This method should return true if the document needs to be encrypted. |
boolean |
isStreamEncrypted()
This method returns true if Streams in the document should be stored encrypted. |
boolean |
isStringEncrypted()
This method returns true if Strings in the document should be stored encrypted. |
void |
prepareToDecrypt()
This method is called just before the PDF is read in. |
void |
prepareToEncrypt()
This method is called when the PDF is about to be written out. |
void |
setAcrobat3Level(boolean print,
boolean annotations,
boolean extraction,
boolean change)
Set the access levels for Acrobat 3 and greater. |
void |
setAcrobat5Level(int print,
int extraction,
int change)
Set the access levels for Acrobat 5 and greater. |
void |
setAcrobat6Level(int print,
int extraction,
int change,
boolean encryptmetadata)
Set the access levels for Acrobat 6 and greater. |
void |
setAcrobat7Level(int print,
int extraction,
int change,
boolean encryptmetadata)
Set the access levels for Acrobat 7 and greater. |
void |
setAcrobat9Level(int print,
int extraction,
int change,
boolean encryptmetadata)
Deprecated. the encryption algorithm used by Acrobat 9 has ben found to be less secure than the algorithm used by Acrobat 7, so as of 2.11.19 a request for Acrobat 9 encryption will fall back to Acrobat 7 encryption. |
void |
setAcrobatXLevel(int print,
int extraction,
int change,
boolean encryptmetadata)
Set the access levels for Acrobat X and greater. |
void |
setOwnerPassword(String password)
Set the "security" password for the PDF document - the password required to change the security settings of the document (the access level and the open password). |
void |
setUserPassword(String password)
Set the password required to open the document (also called the "User" password). |
Methods inherited from class org.faceless.pdf2.EncryptionHandler |
---|
containsKey, getArrayValueSize, getBooleanValue, getDictionaryValueKeys, getFileId, getNameValue, getNumericValue, getStringValue, getTextStringValue, markChanged, putArrayValue, putBooleanValue, putDictionaryValue, putNameValue, putNumericValue, putStringValue, putTextStringValue, setFileId |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int PRINT_NONE
setAcrobat5Level(int, int, int)
to prevent printing altogether
public static final int PRINT_LOWRES
setAcrobat5Level(int, int, int)
to limit printing to lo-res (theoretically about 150dpi)
public static final int PRINT_HIGHRES
setAcrobat5Level(int, int, int)
to allow full print access
public static final int EXTRACT_NONE
setAcrobat5Level(int, int, int)
to prevent any copying of images of text
public static final int EXTRACT_ACCESSIBILITY
setAcrobat5Level(int, int, int)
to allow the limited copying of images and text
for the purposes of accessibility for disabled users
public static final int EXTRACT_ALL
setAcrobat5Level(int, int, int)
to allow copying of images and text from the
document.
public static final int CHANGE_NONE
setAcrobat5Level(int, int, int)
to disallow all changes to the document
public static final int CHANGE_LAYOUT
setAcrobat5Level(int, int, int)
to allow only pages to be inserted, deleted, rotated
and reordered
public static final int CHANGE_FORMS
setAcrobat5Level(int, int, int)
to allow only form fields to be completed
public static final int CHANGE_ANNOTATIONS
setAcrobat5Level(int, int, int)
to allow form fields and annotations to be added
or modified
public static final int CHANGE_ALL
setAcrobat5Level(int, int, int)
to allow the document to be modified in any way
Constructor Detail |
---|
public StandardEncryptionHandler()
setAcrobat3Level(true,true,true,true)
)
Method Detail |
---|
public int hashCode()
hashCode
in class Object
public boolean equals(Object o)
equals
in class Object
public Object clone()
clone
in class EncryptionHandler
public void setOwnerPassword(String password)
Set the "security" password for the PDF document - the password required to change the security settings of the document (the access level and the open password). If you don't anticipate changing the security settings at a later date, you can leave this blank.
public void setUserPassword(String password)
public void setAcrobat3Level(boolean print, boolean annotations, boolean extraction, boolean change)
print
- true if the document can be printedannotations
- true if form field and other annotations can be added or editedextraction
- true if text and images can be copied from the documentchange
- true if the document can have pages added, deleted, reordered or rotatedpublic void setAcrobat5Level(int print, int extraction, int change)
Set the access levels for Acrobat 5 and greater. The document will be encrypted using 128-bit RC4 encryption, so that only Acrobat 5.0 and later browsers can open the document.
The various parameter control the level of printing, the level of data extraction and the types of changes that can be made to the document.
print
- one of PRINT_NONE
PRINT_LOWRES
PRINT_HIGHRES
extraction
- one of EXTRACT_NONE
EXTRACT_ACCESSIBILITY
EXTRACT_ALL
change
- one of CHANGE_NONE
CHANGE_LAYOUT
CHANGE_FORMS
CHANGE_ANNOTATIONS
CHANGE_ALL
public void setAcrobat6Level(int print, int extraction, int change, boolean encryptmetadata)
Set the access levels for Acrobat 6 and greater. Acrobat 6 encryption is identical
to Acrobat 5 except that it optionally allows leaving XMP MetaData unencrypted.
Because of this, if the encryptmetadata
param is set to true, this
method is identical to calling setAcrobat5Level(int, int, int)
.
print
- one of PRINT_NONE
PRINT_LOWRES
PRINT_HIGHRES
extraction
- one of EXTRACT_NONE
EXTRACT_ACCESSIBILITY
EXTRACT_ALL
change
- one of CHANGE_NONE
CHANGE_LAYOUT
CHANGE_FORMS
CHANGE_ANNOTATIONS
CHANGE_ALL
encryptmetadata
- whether to encrypt the XMP metadatapublic void setAcrobat7Level(int print, int extraction, int change, boolean encryptmetadata) throws NoSuchAlgorithmException
Set the access levels for Acrobat 7 and greater. Acrobat 7 encryption is identical to Acrobat 6 except that the Advanced Encryption Standard (AES) is used as the block cipher rather than RC4. Documents encrypted with AES can only be opened in Acrobat 7.0 or later. AES encryption requires the JCE to be installed - in practice this means Java 1.4 or later is required.
print
- one of PRINT_NONE
PRINT_LOWRES
PRINT_HIGHRES
extraction
- one of EXTRACT_NONE
EXTRACT_ACCESSIBILITY
EXTRACT_ALL
change
- one of CHANGE_NONE
CHANGE_LAYOUT
CHANGE_FORMS
CHANGE_ANNOTATIONS
CHANGE_ALL
encryptmetadata
- whether to encrypt the XMP metadata
NoSuchAlgorithmException
- if the AES cipher isn't availablepublic void setAcrobat9Level(int print, int extraction, int change, boolean encryptmetadata) throws NoSuchAlgorithmException
Set the access levels for Acrobat 9 and greater. Acrobat 9 encryption is identical to Acrobat 7 except that the key length for the AES block cipher is 256 bit rather than 128. Documents encrypted this way can only be opened with Acrobat 9.0 or later.
Users of Sun JVMs will require the "unlimited strength" policy files to use AES256 encryption, and other JVMs may have similar requirements.
print
- one of PRINT_NONE
PRINT_LOWRES
PRINT_HIGHRES
extraction
- one of EXTRACT_NONE
EXTRACT_ACCESSIBILITY
EXTRACT_ALL
change
- one of CHANGE_NONE
CHANGE_LAYOUT
CHANGE_FORMS
CHANGE_ANNOTATIONS
CHANGE_ALL
encryptmetadata
- whether to encrypt the XMP metadata
NoSuchAlgorithmException
- if the AES cipher isn't availablepublic void setAcrobatXLevel(int print, int extraction, int change, boolean encryptmetadata) throws NoSuchAlgorithmException
Set the access levels for Acrobat X and greater. Acrobat X encryption is identical to Acrobat 7 except that the key length for the AES block cipher is 256 bit rather than 128. Documents encrypted this way can only be opened with Acrobat X or later.
Users of Sun JVMs will require the "unlimited strength" policy files to use AES256 encryption, and other JVMs may have similar requirements.
print
- one of PRINT_NONE
PRINT_LOWRES
PRINT_HIGHRES
extraction
- one of EXTRACT_NONE
EXTRACT_ACCESSIBILITY
EXTRACT_ALL
change
- one of CHANGE_NONE
CHANGE_LAYOUT
CHANGE_FORMS
CHANGE_ANNOTATIONS
CHANGE_ALL
encryptmetadata
- whether to encrypt the XMP metadata
NoSuchAlgorithmException
- if the AES cipher isn't availablepublic int getVersion()
public boolean isOwnerPasswordKnown()
public boolean isMetadataEncrypted()
EncryptionHandler
isMetadataEncrypted
in class EncryptionHandler
public boolean isStreamEncrypted()
EncryptionHandler
isStreamEncrypted
in class EncryptionHandler
public boolean isStringEncrypted()
EncryptionHandler
isStringEncrypted
in class EncryptionHandler
public boolean isEmbeddedFileEncrypted()
EncryptionHandler
isEmbeddedFileEncrypted
in class EncryptionHandler
public int getChange()
CHANGE_NONE
CHANGE_LAYOUT
CHANGE_FORMS
CHANGE_ANNOTATIONS
or CHANGE_ALL
public int getExtract()
EXTRACT_NONE
EXTRACT_ACCESSIBILITY
EXTRACT_ALL
public int getPrint()
PRINT_NONE
PRINT_LOWRES
PRINT_HIGHRES
public boolean hasRight(String right)
EncryptionHandler
super.hasRight()
if it doesn't recognise the value of "right"
hasRight
in class EncryptionHandler
right
- an interned() String defining the usage right the PDF library
is querying.public String getFilterName()
EncryptionHandler
StandardEncryptionHandler
class returns "Standard" from this method.
getFilterName
in class EncryptionHandler
public String getSubFilterName()
EncryptionHandler
null
.
getSubFilterName
in class EncryptionHandler
public String getDescription()
public boolean isRequired()
EncryptionHandler
true
if the document needs to be encrypted.
For example, the StandardEncryptionHandler
returns false
here
if and only if no passwords are set and the document is set to allow full access.
isRequired
in class EncryptionHandler
public int getDecryptedStreamLength(int len)
EncryptionHandler
getDecryptedStreamLength
in class EncryptionHandler
public int getEncryptedStreamLength(int len)
EncryptionHandler
getEncryptedStreamLength
in class EncryptionHandler
public OutputStream getEncryptionStream(OutputStream out, int num, int gen)
EncryptionHandler
FilterOutputStream
that will encrypt anything written
to it. The encryption parameters are set in EncryptionHandler.prepareToEncrypt()
,
which is called once at the start of the render.
getEncryptionStream
in class EncryptionHandler
out
- the OuptutStream that should be written tonum
- the object number of the top-level objectgen
- the generation number of the top-level objectpublic InputStream getDecryptionStream(InputStream in, int num, int gen)
EncryptionHandler
FilterInputStream
that will decrypt anything read
from it. The decryption parameters are set in EncryptionHandler.prepareToDecrypt()
,
which is called once at the start of the PDF read.
getDecryptionStream
in class EncryptionHandler
in
- the InputStream that should be read fromnum
- the object number of the top-level objectgen
- the generation number of the top-level objectpublic void prepareToDecrypt() throws IOException
EncryptionHandler
Encrypt
dictionary by way of the various get...
methods, and use them and the value of EncryptionHandler.getFileId()
to set its internal state so that
it's ready to start decryption. It may throw an IOException
if these parameters
are invalid, in which case the document cannot be read.
prepareToDecrypt
in class EncryptionHandler
IOException
public void prepareToEncrypt() throws IOException
EncryptionHandler
Encrypt
dictionary
(including the "Filter" field) by way of the various put...
methods, and will use
these and the value of EncryptionHandler.getFileId()
to set its internal state so that it's ready to
start encryption. It may throw an IOException
if these parameters are in any
way invalid, in which case the document cannot be written.
prepareToEncrypt
in class EncryptionHandler
IOException
public void finishedEncrypt()
EncryptionHandler
finishedEncrypt
in class EncryptionHandler
public void finishedDecrypt()
EncryptionHandler
finishedDecrypt
in class EncryptionHandler
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |