org.pdfbox.pdmodel.encryption

Class PDStandardEncryption


public class PDStandardEncryption
extends PDEncryptionDictionary

This class holds information that is related to the standard PDF encryption. See PDF Reference 1.4 section "3.5 Encryption"
Version:
$Revision: 1.7 $
Author:
Ben Litchfield

Field Summary

static int
DEFAULT_PERMISSIONS
The default set of permissions which is to allow all.
static int
DEFAULT_REVISION
The default revision of one is not specified.
static String
FILTER_NAME
The 'Filter' name for this security handler.
static int
REVISION2
Encryption revision 2.
static int
REVISION3
Encryption revision 3.
static int
REVISION4
Encryption revision 4.

Fields inherited from class org.pdfbox.pdmodel.encryption.PDEncryptionDictionary

DEFAULT_LENGTH, DEFAULT_NAME, DEFAULT_VERSION, VERSION0_UNDOCUMENTED_UNSUPPORTED, VERSION1_40_BIT_ALGORITHM, VERSION2_VARIABLE_LENGTH_ALGORITHM, VERSION3_UNPUBLISHED_ALGORITHM, VERSION4_SECURITY_HANDLER, encryptionDictionary

Constructor Summary

PDStandardEncryption()
Default constructor that uses Version 2, Revision 3, 40 bit encryption, all permissions allowed.
PDStandardEncryption(COSDictionary dict)
Constructor from existing dictionary.

Method Summary

boolean
canAssembleDocument()
This will tell if the user can insert/rotate/delete pages.
boolean
canExtractContent()
This will tell if the user can extract text and images from the PDF document.
boolean
canExtractForAccessibility()
This will tell if the user can extract text and images from the PDF document for accessibility purposes.
boolean
canFillInForm()
This will tell if the user can fill in interactive forms.
boolean
canModify()
This will tell if the user can modify contents of the document.
boolean
canModifyAnnotations()
This will tell if the user can add/modify text annotations, fill in interactive forms fields.
boolean
canPrint()
This will tell if the user can print.
boolean
canPrintDegraded()
This will tell if the user can print the document in a degraded format.
byte[]
getOwnerKey()
This will get the O entry in the standard encryption dictionary.
int
getPermissions()
This will get the permissions bit mask.
int
getRevision()
This will return the R entry of the encryption dictionary.

See PDF Reference 1.4 Table 3.14.
byte[]
getUserKey()
This will get the U entry in the standard encryption dictionary.
void
setCanAssembleDocument(boolean allowAssembly)
Set if the user can insert/rotate/delete pages.
void
setCanExtractContent(boolean allowExtraction)
Set if the user can extract content from the document.
void
setCanExtractForAccessibility(boolean allowExtraction)
Set if the user can extract content from the document for accessibility purposes.
void
setCanFillInForm(boolean allowFillingInForm)
Set if the user can fill in interactive forms.
void
setCanModify(boolean allowModifications)
Set if the user can modify the document.
void
setCanModifyAnnotations(boolean allowAnnotationModification)
Set if the user can modify annotations.
void
setCanPrint(boolean allowPrinting)
Set if the user can print.
void
setCanPrintDegraded(boolean allowAssembly)
Set if the user can print the document in a degraded format.
void
setOwnerKey(byte[] o)
This will set the O entry in the standard encryption dictionary.
void
setPermissions(int p)
This will set the permissions bit mask.
void
setRevision(int revision)
This will set the R entry of the encryption dictionary.

See PDF Reference 1.4 Table 3.14.
void
setUserKey(byte[] u)
This will set the U entry in the standard encryption dictionary.

Methods inherited from class org.pdfbox.pdmodel.encryption.PDEncryptionDictionary

getCOSDictionary, getFilter, getLength, getOwnerKey, getPermissions, getRecipientStringAt, getRecipientsLength, getRevision, getUserKey, getVersion, setFilter, setLength, setOwnerKey, setPermissions, setRecipients, setRevision, setSubFilter, setUserKey, setVersion

Field Details

DEFAULT_PERMISSIONS

public static final int DEFAULT_PERMISSIONS
The default set of permissions which is to allow all.
Field Value:
-4

DEFAULT_REVISION

public static final int DEFAULT_REVISION
The default revision of one is not specified.
Field Value:
3

FILTER_NAME

public static final String FILTER_NAME
The 'Filter' name for this security handler.

REVISION2

public static final int REVISION2
Encryption revision 2.
Field Value:
2

REVISION3

public static final int REVISION3
Encryption revision 3.
Field Value:
3

REVISION4

public static final int REVISION4
Encryption revision 4.
Field Value:
4

Constructor Details

PDStandardEncryption

public PDStandardEncryption()
Default constructor that uses Version 2, Revision 3, 40 bit encryption, all permissions allowed.

PDStandardEncryption

public PDStandardEncryption(COSDictionary dict)
Constructor from existing dictionary.
Parameters:
dict - The existing encryption dictionary.

Method Details

canAssembleDocument

public boolean canAssembleDocument()
This will tell if the user can insert/rotate/delete pages.
Returns:
true If supplied with the user password they are allowed to extract content from the PDF document

canExtractContent

public boolean canExtractContent()
This will tell if the user can extract text and images from the PDF document.
Returns:
true If supplied with the user password they are allowed to extract content from the PDF document

canExtractForAccessibility

public boolean canExtractForAccessibility()
This will tell if the user can extract text and images from the PDF document for accessibility purposes.
Returns:
true If supplied with the user password they are allowed to extract content from the PDF document

canFillInForm

public boolean canFillInForm()
This will tell if the user can fill in interactive forms.
Returns:
true If supplied with the user password they are allowed to fill in form fields.

canModify

public boolean canModify()
This will tell if the user can modify contents of the document.
Returns:
true If supplied with the user password they are allowed to modify the document

canModifyAnnotations

public boolean canModifyAnnotations()
This will tell if the user can add/modify text annotations, fill in interactive forms fields.
Returns:
true If supplied with the user password they are allowed to modify annotations.

canPrint

public boolean canPrint()
This will tell if the user can print.
Returns:
true If supplied with the user password they are allowed to print.

canPrintDegraded

public boolean canPrintDegraded()
This will tell if the user can print the document in a degraded format.
Returns:
true If supplied with the user password they are allowed to print the document in a degraded format.

getOwnerKey

public byte[] getOwnerKey()
This will get the O entry in the standard encryption dictionary.
Overrides:
getOwnerKey in interface PDEncryptionDictionary
Returns:
A 32 byte array or null if there is no owner key.

getPermissions

public int getPermissions()
This will get the permissions bit mask.
Overrides:
getPermissions in interface PDEncryptionDictionary
Returns:
The permissions bit mask.

getRevision

public int getRevision()
This will return the R entry of the encryption dictionary.

See PDF Reference 1.4 Table 3.14.
Overrides:
getRevision in interface PDEncryptionDictionary
Returns:
The encryption revision to use.

getUserKey

public byte[] getUserKey()
This will get the U entry in the standard encryption dictionary.
Overrides:
getUserKey in interface PDEncryptionDictionary
Returns:
A 32 byte array or null if there is no user key.

setCanAssembleDocument

public void setCanAssembleDocument(boolean allowAssembly)
Set if the user can insert/rotate/delete pages.
Parameters:
allowAssembly - A boolean determining if the user can assemble the document.

setCanExtractContent

public void setCanExtractContent(boolean allowExtraction)
Set if the user can extract content from the document.
Parameters:
allowExtraction - A boolean determining if the user can extract content from the document.

setCanExtractForAccessibility

public void setCanExtractForAccessibility(boolean allowExtraction)
Set if the user can extract content from the document for accessibility purposes.
Parameters:
allowExtraction - A boolean determining if the user can extract content from the document.

setCanFillInForm

public void setCanFillInForm(boolean allowFillingInForm)
Set if the user can fill in interactive forms.
Parameters:
allowFillingInForm - A boolean determining if the user can fill in interactive forms.

setCanModify

public void setCanModify(boolean allowModifications)
Set if the user can modify the document.
Parameters:
allowModifications - A boolean determining if the user can modify the document.

setCanModifyAnnotations

public void setCanModifyAnnotations(boolean allowAnnotationModification)
Set if the user can modify annotations.
Parameters:
allowAnnotationModification - A boolean determining if the user can modify annotations.

setCanPrint

public void setCanPrint(boolean allowPrinting)
Set if the user can print.
Parameters:
allowPrinting - A boolean determining if the user can print.

setCanPrintDegraded

public void setCanPrintDegraded(boolean allowAssembly)
Set if the user can print the document in a degraded format.
Parameters:
allowAssembly - A boolean determining if the user can print the document in a degraded format.

setOwnerKey

public void setOwnerKey(byte[] o)
            throws IOException
This will set the O entry in the standard encryption dictionary.
Overrides:
setOwnerKey in interface PDEncryptionDictionary
Parameters:
o - A 32 byte array or null if there is no owner key.

setPermissions

public void setPermissions(int p)
This will set the permissions bit mask.
Overrides:
setPermissions in interface PDEncryptionDictionary
Parameters:
p - The new permissions bit mask

setRevision

public void setRevision(int revision)
This will set the R entry of the encryption dictionary.

See PDF Reference 1.4 Table 3.14.

Note: This value is used to decrypt the pdf document. If you change this when the document is encrypted then decryption will fail!.
Overrides:
setRevision in interface PDEncryptionDictionary
Parameters:
revision - The new encryption version.

setUserKey

public void setUserKey(byte[] u)
            throws IOException
This will set the U entry in the standard encryption dictionary.
Overrides:
setUserKey in interface PDEncryptionDictionary
Parameters:
u - A 32 byte array.