java.lang.Object
org.sejda.sambox.pdmodel.common.PDDictionaryWrapper
org.sejda.sambox.pdmodel.encryption.PDEncryption
- All Implemented Interfaces:
COSObjectable
This class is a specialized view of the encryption getCOSObject() of a PDF document. It contains a low level
getCOSObject() (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.
- Author:
- Ben Litchfield, Benoit Guillon
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default length for the encryption key.static final intThe default version, according to the PDF Reference.static final intSee PDF Reference 1.4 Table 3.13.static final intSee PDF Reference 1.4 Table 3.13.static final intSee PDF Reference 1.4 Table 3.13.static final intSee PDF Reference 1.4 Table 3.13.static final intSee PDF Reference 1.4 Table 3.13. -
Constructor Summary
ConstructorsConstructorDescriptioncreates a new empty encryption getCOSObject().PDEncryption(COSDictionary dictionary) creates a new encryption getCOSObject() from the low level getCOSObject() provided. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.getCryptFilterDictionary(COSName cryptFilterName) Returns the crypt filter with the given name.final StringGet the name of the filter.intThis will return the Length entry of the encryption getCOSObject().
The length in bits for the encryption algorithm.byte[]This will get the OE entry in the standard encryption getCOSObject().byte[]This will get the O entry in the standard encryption getCOSObject().intThis will get the permissions bit mask.byte[]getPerms()Get the Perms entry in the encryption getCOSObject().intReturns the number of recipients contained in the Recipients field of the getCOSObject().getRecipientStringAt(int i) returns the COSString contained in the Recipients field at position i.intThis will return the R entry of the encryption getCOSObject().
See PDF Reference 1.4 Table 3.14.Returns the security handler specified in the getCOSObject()'s Filter entry.Returns the name of the filter which is used for de/encrypting streams.Returns the name of the filter which is used for de/encrypting strings.Get the name of the subfilter.byte[]This will get the UE entry in the standard encryption getCOSObject().byte[]This will get the U entry in the standard encryption getCOSObject().intThis will return the V entry of the encryption getCOSObject().
See PDF Reference 1.4 Table 3.13.booleanReturns true if the security handler specified in the getCOSObject()'s Filter is available.booleanWill get the EncryptMetaData getCOSObject() info.voidremove CF, StmF, and StrF entries.voidsetCryptFilterDictionary(COSName cryptFilterName, PDCryptFilterDictionary cryptFilterDictionary) Sets the crypt filter with the given name.voidsetDefaultCryptFilterDictionary(PDCryptFilterDictionary defaultFilterDictionary) Sets the default crypt filter (for public-key security handler).voidSets the filter entry of the encryption getCOSObject().voidsetLength(int length) This will set the number of bits to use for the encryption algorithm.voidsetOwnerEncryptionKey(byte[] oe) This will set the OE entry in the standard encryption getCOSObject().voidsetOwnerKey(byte[] o) This will set the O entry in the standard encryption getCOSObject().voidsetPermissions(int permissions) This will set the permissions bit mask.voidsetPerms(byte[] perms) Set the Perms entry in the encryption getCOSObject().voidsetRecipients(byte[][] recipients) This will set the Recipients field of the getCOSObject().voidsetRevision(int revision) This will set the R entry of the encryption getCOSObject().
See PDF Reference 1.4 Table 3.14.voidsetSecurityHandler(SecurityHandler securityHandler) Sets the security handler used in this encryption getCOSObject()voidsetStdCryptFilterDictionary(PDCryptFilterDictionary cryptFilterDictionary) Sets the standard crypt filter.voidsetStreamFilterName(COSName streamFilterName) Sets the name of the filter which is used for de/encrypting streams.voidsetStringFilterName(COSName stringFilterName) Sets the name of the filter which is used for de/encrypting strings.voidsetSubFilter(String subfilter) Set the subfilter entry of the encryption getCOSObject().voidsetUserEncryptionKey(byte[] ue) This will set the UE entry in the standard encryption getCOSObject().voidsetUserKey(byte[] u) This will set the U entry in the standard encryption getCOSObject().voidsetVersion(int version) This will set the V entry of the encryption getCOSObject().
See PDF Reference 1.4 Table 3.13.Methods inherited from class org.sejda.sambox.pdmodel.common.PDDictionaryWrapper
equals, getCOSObject, hashCode
-
Field Details
-
VERSION0_UNDOCUMENTED_UNSUPPORTED
public static final int VERSION0_UNDOCUMENTED_UNSUPPORTEDSee PDF Reference 1.4 Table 3.13.- See Also:
-
VERSION1_40_BIT_ALGORITHM
public static final int VERSION1_40_BIT_ALGORITHMSee PDF Reference 1.4 Table 3.13.- See Also:
-
VERSION2_VARIABLE_LENGTH_ALGORITHM
public static final int VERSION2_VARIABLE_LENGTH_ALGORITHMSee PDF Reference 1.4 Table 3.13.- See Also:
-
VERSION3_UNPUBLISHED_ALGORITHM
public static final int VERSION3_UNPUBLISHED_ALGORITHMSee PDF Reference 1.4 Table 3.13.- See Also:
-
VERSION4_SECURITY_HANDLER
public static final int VERSION4_SECURITY_HANDLERSee PDF Reference 1.4 Table 3.13.- See Also:
-
DEFAULT_LENGTH
public static final int DEFAULT_LENGTHThe default length for the encryption key.- See Also:
-
DEFAULT_VERSION
public static final int DEFAULT_VERSIONThe default version, according to the PDF Reference.- See Also:
-
-
Constructor Details
-
PDEncryption
public PDEncryption()creates a new empty encryption getCOSObject(). -
PDEncryption
creates a new encryption getCOSObject() from the low level getCOSObject() provided.- Parameters:
getCOSObject- () a COS encryption getCOSObject()
-
-
Method Details
-
getSecurityHandler
Returns the security handler specified in the getCOSObject()'s Filter entry.- Returns:
- a security handler instance
- Throws:
IOException- if there is no security handler available which matches the Filter
-
setSecurityHandler
Sets the security handler used in this encryption getCOSObject()- Parameters:
securityHandler- new security handler
-
hasSecurityHandler
public boolean hasSecurityHandler()Returns true if the security handler specified in the getCOSObject()'s Filter is available.- Returns:
- true if the security handler is available
-
getCOSDictionary
Deprecated.This will get the getCOSObject() associated with this encryption getCOSObject().- Returns:
- The COS getCOSObject() that this object wraps.
-
setFilter
Sets the filter entry of the encryption getCOSObject().- Parameters:
filter- The filter name.
-
getFilter
Get the name of the filter.- Returns:
- The filter name contained in this encryption getCOSObject().
-
getSubFilter
Get the name of the subfilter.- Returns:
- The subfilter name contained in this encryption getCOSObject().
-
setSubFilter
Set the subfilter entry of the encryption getCOSObject().- Parameters:
subfilter- The value of the subfilter field.
-
setVersion
public void setVersion(int version) This will set the V entry of the encryption getCOSObject().
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 getCOSObject().
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 getCOSObject().
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 getCOSObject().
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 getCOSObject().
See PDF Reference 1.4 Table 3.14.- Returns:
- The encryption revision to use.
-
setOwnerKey
public void setOwnerKey(byte[] o) This will set the O entry in the standard encryption getCOSObject().- Parameters:
o- A 32 byte array or null if there is no owner key.- Throws:
IOException- If there is an error setting the data.
-
getOwnerKey
public byte[] getOwnerKey()This will get the O entry in the standard encryption getCOSObject().- Returns:
- A 32 byte array or null if there is no owner key.
- Throws:
IOException- If there is an error accessing the data.
-
setUserKey
public void setUserKey(byte[] u) This will set the U entry in the standard encryption getCOSObject().- Parameters:
u- A 32 byte array.- Throws:
IOException- If there is an error setting the data.
-
getUserKey
public byte[] getUserKey()This will get the U entry in the standard encryption getCOSObject().- Returns:
- A 32 byte array or null if there is no user key.
- Throws:
IOException- If there is an error accessing the data.
-
setOwnerEncryptionKey
public void setOwnerEncryptionKey(byte[] oe) This will set the OE entry in the standard encryption getCOSObject().- Parameters:
oe- A 32 byte array or null if there is no owner encryption key.- Throws:
IOException- If there is an error setting the data.
-
getOwnerEncryptionKey
public byte[] getOwnerEncryptionKey()This will get the OE entry in the standard encryption getCOSObject().- Returns:
- A 32 byte array or null if there is no owner encryption key.
- Throws:
IOException- If there is an error accessing the data.
-
setUserEncryptionKey
public void setUserEncryptionKey(byte[] ue) This will set the UE entry in the standard encryption getCOSObject().- Parameters:
ue- A 32 byte array or null if there is no user encryption key.- Throws:
IOException- If there is an error setting the data.
-
getUserEncryptionKey
public byte[] getUserEncryptionKey()This will get the UE entry in the standard encryption getCOSObject().- Returns:
- A 32 byte array or null if there is no user encryption key.
- Throws:
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 getCOSObject() info.- Returns:
- true if EncryptMetaData is explicitly set to false (the default is true)
-
setRecipients
public void setRecipients(byte[][] recipients) This will set the Recipients field of the getCOSObject(). This field contains an array of string.- Parameters:
recipients- the array of bytes arrays to put in the Recipients field.- Throws:
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 getCOSObject().- Returns:
- the number of recipients contained in the Recipients field.
-
getRecipientStringAt
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
- Returns:
- the standard crypt filter if available.
-
getDefaultCryptFilterDictionary
- Returns:
- the default crypt filter if available.
-
getCryptFilterDictionary
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
-
setCryptFilterDictionary
public void setCryptFilterDictionary(COSName cryptFilterName, PDCryptFilterDictionary cryptFilterDictionary) Sets the crypt filter with the given name.- Parameters:
cryptFilterName- the name of the crypt filtercryptFilterDictionary- the crypt filter to set
-
setStdCryptFilterDictionary
Sets the standard crypt filter.- Parameters:
cryptFilterDictionary- the standard crypt filter to set
-
setDefaultCryptFilterDictionary
Sets the default crypt filter (for public-key security handler).- Parameters:
defaultFilterDictionary- the standard crypt filter to set
-
getStreamFilterName
Returns the name of the filter which is used for de/encrypting streams. Default value is "Identity".- Returns:
- the name of the filter
-
setStreamFilterName
Sets the name of the filter which is used for de/encrypting streams.- Parameters:
streamFilterName- the name of the filter
-
getStringFilterName
Returns the name of the filter which is used for de/encrypting strings. Default value is "Identity".- Returns:
- the name of the filter
-
setStringFilterName
Sets the name of the filter which is used for de/encrypting strings.- Parameters:
stringFilterName- the name of the filter
-
setPerms
public void setPerms(byte[] perms) Set the Perms entry in the encryption getCOSObject().- Parameters:
perms- A 16 byte array.- Throws:
IOException- If there is an error setting the data.
-
getPerms
public byte[] getPerms()Get the Perms entry in the encryption getCOSObject().- Returns:
- A 16 byte array or null if there is no Perms entry.
- Throws:
IOException- If there is an error accessing the data.
-
removeV45filters
public void removeV45filters()remove CF, StmF, and StrF entries. This is to be called if V is not 4 or 5.
-