Class PDEncryptionDictionary
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.encryption.PDEncryptionDictionary
-
- Direct Known Subclasses:
PDStandardEncryption
public class PDEncryptionDictionary extends java.lang.ObjectThis class is a specialized view of the encryption dictionary of a PDF document. It contains a low level dictionary (COSDictionary) and provides the methods to manage its fields. The available fields are the ones who are involved by standard security handler and public key security handler.- Version:
- $Revision: 1.7 $
- Author:
- Ben Litchfield, Benoit Guillon (benoit.guillon@snv.jussieu.fr)
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_LENGTHThe default length for the encryption key.static java.lang.StringDEFAULT_NAMEThe default security handler.static intDEFAULT_VERSIONThe default version, according to the PDF Reference.protected COSDictionaryencryptionDictionaryCOS encryption dictionary.static intVERSION0_UNDOCUMENTED_UNSUPPORTEDSee PDF Reference 1.4 Table 3.13.static intVERSION1_40_BIT_ALGORITHMSee PDF Reference 1.4 Table 3.13.static intVERSION2_VARIABLE_LENGTH_ALGORITHMSee PDF Reference 1.4 Table 3.13.static intVERSION3_UNPUBLISHED_ALGORITHMSee PDF Reference 1.4 Table 3.13.static intVERSION4_SECURITY_HANDLERSee PDF Reference 1.4 Table 3.13.
-
Constructor Summary
Constructors Constructor Description PDEncryptionDictionary()creates a new empty encryption dictionary.PDEncryptionDictionary(COSDictionary d)creates a new encryption dictionary from the low level dictionary provided.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description COSDictionarygetCOSDictionary()This will get the dictionary associated with this encryption dictionary.PDCryptFilterDictionarygetCryptFilterDictionary(COSName cryptFilterName)Returns the crypt filter with the given name.java.lang.StringgetFilter()Get the name of the filter.intgetLength()This will return the Length entry of the encryption dictionary.
The length in bits for the encryption algorithm.byte[]getOwnerKey()This will get the O entry in the standard encryption dictionary.intgetPermissions()This will get the permissions bit mask.intgetRecipientsLength()Returns the number of recipients contained in the Recipients field of the dictionary.COSStringgetRecipientStringAt(int i)returns the COSString contained in the Recipients field at position i.intgetRevision()This will return the R entry of the encryption dictionary.
See PDF Reference 1.4 Table 3.14.PDCryptFilterDictionarygetStdCryptFilterDictionary()Returns the standard crypt filter.COSNamegetStreamFilterName()Returns the name of the filter which is used for de/encrypting streams.COSNamegetStringFilterName()Returns the name of the filter which is used for de/encrypting strings.java.lang.StringgetSubFilter()Get the name of the subfilter.byte[]getUserKey()This will get the U entry in the standard encryption dictionary.intgetVersion()This will return the V entry of the encryption dictionary.
See PDF Reference 1.4 Table 3.13.booleanisEncryptMetaData()Will get the EncryptMetaData dictionary info.voidsetFilter(java.lang.String filter)Sets the filter entry of the encryption dictionary.voidsetLength(int length)This will set the number of bits to use for the encryption algorithm.voidsetOwnerKey(byte[] o)This will set the O entry in the standard encryption dictionary.voidsetPermissions(int permissions)This will set the permissions bit mask.voidsetRecipients(byte[][] recipients)This will set the Recipients field of the dictionary.voidsetRevision(int revision)This will set the R entry of the encryption dictionary.
See PDF Reference 1.4 Table 3.14.voidsetSubFilter(java.lang.String subfilter)Set the subfilter entry of the encryption dictionary.voidsetUserKey(byte[] u)This will set the U entry in the standard encryption dictionary.voidsetVersion(int version)This will set the V entry of the encryption dictionary.
See PDF Reference 1.4 Table 3.13.
-
-
-
Field Detail
-
VERSION0_UNDOCUMENTED_UNSUPPORTED
public static final int VERSION0_UNDOCUMENTED_UNSUPPORTED
See PDF Reference 1.4 Table 3.13.- See Also:
- Constant Field Values
-
VERSION1_40_BIT_ALGORITHM
public static final int VERSION1_40_BIT_ALGORITHM
See PDF Reference 1.4 Table 3.13.- See Also:
- Constant Field Values
-
VERSION2_VARIABLE_LENGTH_ALGORITHM
public static final int VERSION2_VARIABLE_LENGTH_ALGORITHM
See PDF Reference 1.4 Table 3.13.- See Also:
- Constant Field Values
-
VERSION3_UNPUBLISHED_ALGORITHM
public static final int VERSION3_UNPUBLISHED_ALGORITHM
See PDF Reference 1.4 Table 3.13.- See Also:
- Constant Field Values
-
VERSION4_SECURITY_HANDLER
public static final int VERSION4_SECURITY_HANDLER
See PDF Reference 1.4 Table 3.13.- See Also:
- Constant Field Values
-
DEFAULT_NAME
public static final java.lang.String DEFAULT_NAME
The default security handler.- See Also:
- Constant Field Values
-
DEFAULT_LENGTH
public static final int DEFAULT_LENGTH
The default length for the encryption key.- See Also:
- Constant Field Values
-
DEFAULT_VERSION
public static final int DEFAULT_VERSION
The default version, according to the PDF Reference.- See Also:
- Constant Field Values
-
encryptionDictionary
protected COSDictionary encryptionDictionary
COS encryption dictionary.
-
-
Constructor Detail
-
PDEncryptionDictionary
public PDEncryptionDictionary()
creates a new empty encryption dictionary.
-
PDEncryptionDictionary
public PDEncryptionDictionary(COSDictionary d)
creates a new encryption dictionary from the low level dictionary provided.- Parameters:
d- the low level dictionary that will be managed by the newly created object
-
-
Method Detail
-
getCOSDictionary
public COSDictionary getCOSDictionary()
This will get the dictionary associated with this encryption dictionary.- Returns:
- The COS dictionary that this object wraps.
-
setFilter
public void setFilter(java.lang.String filter)
Sets the filter entry of the encryption dictionary.- Parameters:
filter- The filter name.
-
getFilter
public java.lang.String getFilter()
Get the name of the filter.- Returns:
- The filter name contained in this encryption dictionary.
-
getSubFilter
public java.lang.String getSubFilter()
Get the name of the subfilter.- Returns:
- The subfilter name contained in this encryption dictionary.
-
setSubFilter
public void setSubFilter(java.lang.String subfilter)
Set the subfilter entry of the encryption dictionary.- Parameters:
subfilter- The value of the subfilter field.
-
setVersion
public void setVersion(int version)
This will set the V entry of the encryption dictionary.
See PDF Reference 1.4 Table 3.13.
Note: This value is used to decrypt the pdf document. If you change this when the document is encrypted then decryption will fail!.- Parameters:
version- The new encryption version.
-
getVersion
public int getVersion()
This will return the V entry of the encryption dictionary.
See PDF Reference 1.4 Table 3.13.- Returns:
- The encryption version to use.
-
setLength
public void setLength(int length)
This will set the number of bits to use for the encryption algorithm.- Parameters:
length- The new key length.
-
getLength
public int getLength()
This will return the Length entry of the encryption dictionary.
The length in bits for the encryption algorithm. This will return a multiple of 8.- Returns:
- The length in bits for the encryption algorithm
-
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!.- Parameters:
revision- The new encryption version.
-
getRevision
public int getRevision()
This will return the R entry of the encryption dictionary.
See PDF Reference 1.4 Table 3.14.- Returns:
- The encryption revision to use.
-
setOwnerKey
public void setOwnerKey(byte[] o) throws java.io.IOExceptionThis will set the O entry in the standard encryption dictionary.- Parameters:
o- A 32 byte array or null if there is no owner key.- Throws:
java.io.IOException- If there is an error setting the data.
-
getOwnerKey
public byte[] getOwnerKey() throws java.io.IOExceptionThis will get the O entry in the standard encryption dictionary.- Returns:
- A 32 byte array or null if there is no owner key.
- Throws:
java.io.IOException- If there is an error accessing the data.
-
setUserKey
public void setUserKey(byte[] u) throws java.io.IOExceptionThis will set the U entry in the standard encryption dictionary.- Parameters:
u- A 32 byte array.- Throws:
java.io.IOException- If there is an error setting the data.
-
getUserKey
public byte[] getUserKey() throws java.io.IOExceptionThis will get the U entry in the standard encryption dictionary.- Returns:
- A 32 byte array or null if there is no user key.
- Throws:
java.io.IOException- If there is an error accessing the data.
-
setPermissions
public void setPermissions(int permissions)
This will set the permissions bit mask.- Parameters:
permissions- The new permissions bit mask
-
getPermissions
public int getPermissions()
This will get the permissions bit mask.- Returns:
- The permissions bit mask.
-
isEncryptMetaData
public boolean isEncryptMetaData()
Will get the EncryptMetaData dictionary info.- Returns:
- true if EncryptMetaData is explicitly set to false (the default is true)
-
setRecipients
public void setRecipients(byte[][] recipients) throws java.io.IOExceptionThis will set the Recipients field of the dictionary. This field contains an array of string.- Parameters:
recipients- the array of bytes arrays to put in the Recipients field.- Throws:
java.io.IOException- If there is an error setting the data.
-
getRecipientsLength
public int getRecipientsLength()
Returns the number of recipients contained in the Recipients field of the dictionary.- Returns:
- the number of recipients contained in the Recipients field.
-
getRecipientStringAt
public COSString getRecipientStringAt(int i)
returns the COSString contained in the Recipients field at position i.- Parameters:
i- the position in the Recipients field array.- Returns:
- a COSString object containing information about the recipient number i.
-
getStdCryptFilterDictionary
public PDCryptFilterDictionary getStdCryptFilterDictionary()
Returns the standard crypt filter.- Returns:
- the standard crypt filter if available.
-
getCryptFilterDictionary
public PDCryptFilterDictionary getCryptFilterDictionary(COSName cryptFilterName)
Returns the crypt filter with the given name.- Parameters:
cryptFilterName- the name of the crypt filter- Returns:
- the crypt filter with the given name if available
-
getStreamFilterName
public COSName getStreamFilterName()
Returns the name of the filter which is used for de/encrypting streams. Default value is "Identity".- Returns:
- the name of the filter
-
getStringFilterName
public COSName getStringFilterName()
Returns the name of the filter which is used for de/encrypting strings. Default value is "Identity".- Returns:
- the name of the filter
-
-