Class StandardDecrypter
java.lang.Object
org.loboevolution.pdfview.decrypt.StandardDecrypter
- All Implemented Interfaces:
PDFDecrypter
Standard simple decrypter for versions 1, 2 and 4 of the Standard
password-based decryption mechanisms, as described in section 3.5 of
the PDF Reference version 1.7.
Author Luke Kirby
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Describes an encryption algorithm to be used, declaring not only the cipher type, but also key generation techniques -
Constructor Summary
ConstructorDescriptionStandardDecrypter
(StandardDecrypter.EncryptionAlgorithm encryptionAlgorithm, PDFObject documentId, int keyBitLength, int revision, byte[] oValue, byte[] uValue, int pValue, boolean encryptMetadata, PDFPassword password) Class constructor -
Method Summary
Modifier and TypeMethodDescriptiondecryptBuffer
(String cryptFilterName, PDFObject streamObj, ByteBuffer streamBuf) Decrypt a buffer of datadecryptString
(int objNum, int objGen, String inputBasicString) Decrypt abasic string
.boolean
Determine whether this actually applies a decryption other than identity decryption.boolean
isEncryptionPresent
(String cryptFilterName) Determines whether decryption applies for a given crypt filter nameboolean
Determine whether the password known by the decrypter indicates that the user is the owner of the document.
-
Constructor Details
-
StandardDecrypter
public StandardDecrypter(StandardDecrypter.EncryptionAlgorithm encryptionAlgorithm, PDFObject documentId, int keyBitLength, int revision, byte[] oValue, byte[] uValue, int pValue, boolean encryptMetadata, PDFPassword password) throws IOException, EncryptionUnsupportedByProductException, EncryptionUnsupportedByPlatformException Class constructor- Parameters:
encryptionAlgorithm
- the algorithm used for encryptiondocumentId
- the contents of the ID entry of the document's trailer dictionary; can be null, but according to the spec, shouldn't be. Is expected to be an array of two byte sequences.keyBitLength
- the length of the key in bits; should be a multiple of 8 between 40 and 128revision
- the revision of the Standard encryption security handler being employed. Should be 2, 3 or 4.oValue
- the value of the O entry from the Encrypt dictionaryuValue
- the value of the U entry from the Encrypt dictionarypValue
- the value of the P entry from the Encrypt dictionaryencryptMetadata
- whether metadata is being encrypted, as identified by the Encrypt dict (with default true if not explicitly identified)password
- the password; not null- Throws:
IOException
- if any.EncryptionUnsupportedByProductException
- if any.EncryptionUnsupportedByPlatformException
- if any.
-
-
Method Details
-
decryptBuffer
public ByteBuffer decryptBuffer(String cryptFilterName, PDFObject streamObj, ByteBuffer streamBuf) throws PDFParseException Decrypt a buffer of data- Specified by:
decryptBuffer
in interfacePDFDecrypter
- Parameters:
cryptFilterName
- the name of the crypt filter, if V4 encryption is being used, where individual crypt filters may be specified for individual streams. If encryption is not using V4 encryption (indicated by V=4 in the Encrypt dictionary) then this must be null. Null may also be specified with V4 encryption to indicate that the default filter should be used.streamObj
- the object whose stream is being decrypted. The containing object's number and generation contribute to the key used for stream encrypted with the document's default encryption, so this is typically required. Should be null only if a cryptFilterName is specified, as objects with specific stream filters use the general document key, rather than a stream-specific key.streamBuf
- the buffer to decrypt- Returns:
- a buffer containing the decrypted stream, positioned at its beginning; will only be the same buffer as streamBuf if the identity decrypter is being used
- Throws:
PDFParseException
- if any.
-
decryptString
public String decryptString(int objNum, int objGen, String inputBasicString) throws PDFParseException Decrypt abasic string
.- Specified by:
decryptString
in interfacePDFDecrypter
- Parameters:
objNum
- the object number of the containing objectobjGen
- the generation number of the containing objectinputBasicString
- the string to be decrypted- Returns:
- the decrypted string
- Throws:
PDFParseException
- if any.
-
isOwnerAuthorised
public boolean isOwnerAuthorised()Determine whether the password known by the decrypter indicates that the user is the owner of the document. Can be used, in conjunction withPDFDecrypter.isEncryptionPresent()
to determine whether any permissions apply.- Specified by:
isOwnerAuthorised
in interfacePDFDecrypter
- Returns:
- whether owner authentication is being used to decrypt the document
-
isEncryptionPresent
public boolean isEncryptionPresent()Determine whether this actually applies a decryption other than identity decryption.- Specified by:
isEncryptionPresent
in interfacePDFDecrypter
- Returns:
- whether encryption is present
-
isEncryptionPresent
Determines whether decryption applies for a given crypt filter name- Specified by:
isEncryptionPresent
in interfacePDFDecrypter
- Parameters:
cryptFilterName
- the crypt filter name- Returns:
- whether the given crypt filter decrypts or not
-