com.sun.pdfview.decrypt
Class StandardDecrypter

java.lang.Object
  extended by com.sun.pdfview.decrypt.StandardDecrypter
All Implemented Interfaces:
PDFDecrypter

public class StandardDecrypter
extends java.lang.Object
implements 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.


Nested Class Summary
static class StandardDecrypter.EncryptionAlgorithm
          Describes an encryption algorithm to be used, declaring not only the cipher type, but also key generation techniques
 
Constructor Summary
StandardDecrypter(StandardDecrypter.EncryptionAlgorithm encryptionAlgorithm, PDFObject documentId, int keyBitLength, int revision, byte[] oValue, byte[] uValue, int pValue, boolean encryptMetadata, PDFPassword password)
          Class constructor
 
Method Summary
 java.nio.ByteBuffer decryptBuffer(java.lang.String cryptFilterName, PDFObject streamObj, java.nio.ByteBuffer streamBuf)
          Decrypt a buffer of data
 java.lang.String decryptString(int objNum, int objGen, java.lang.String inputBasicString)
          Decrypt a basic string.
 boolean isEncryptionPresent()
          Determine whether this actually applies a decryption other than identity decryption.
 boolean isEncryptionPresent(java.lang.String cryptFilterName)
          Determines whether decryption applies for a given crypt filter name
 boolean isOwnerAuthorised()
          Determine whether the password known by the decrypter indicates that the user is the owner of the document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardDecrypter

public StandardDecrypter(StandardDecrypter.EncryptionAlgorithm encryptionAlgorithm,
                         PDFObject documentId,
                         int keyBitLength,
                         int revision,
                         byte[] oValue,
                         byte[] uValue,
                         int pValue,
                         boolean encryptMetadata,
                         PDFPassword password)
                  throws java.io.IOException,
                         EncryptionUnsupportedByProductException,
                         EncryptionUnsupportedByPlatformException
Class constructor

Parameters:
encryptionAlgorithm - the algorithm used for encryption
documentId - 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 128
revision - 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 dictionary
uValue - the value of the U entry from the Encrypt dictionary
pValue - the value of the P entry from the Encrypt dictionary
encryptMetadata - whether metadata is being encrypted, as identified by the Encrypt dict (with default true if not explicitly identified)
password - the password; not null
Throws:
java.io.IOException - if there's a problem reading the file
EncryptionUnsupportedByPlatformException - if the encryption is not supported by the environment in which the code is executing
EncryptionUnsupportedByProductException - if PDFRenderer does not currently support the specified encryption
Method Detail

decryptBuffer

public java.nio.ByteBuffer decryptBuffer(java.lang.String cryptFilterName,
                                         PDFObject streamObj,
                                         java.nio.ByteBuffer streamBuf)
                                  throws PDFParseException
Description copied from interface: PDFDecrypter
Decrypt a buffer of data

Specified by:
decryptBuffer in interface PDFDecrypter
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 the named crypt filter does not exist, or if a crypt filter is named when named crypt filters are not supported. Problems due to incorrect passwords are revealed prior to this point.

decryptString

public java.lang.String decryptString(int objNum,
                                      int objGen,
                                      java.lang.String inputBasicString)
                               throws PDFParseException
Description copied from interface: PDFDecrypter
Decrypt a basic string.

Specified by:
decryptString in interface PDFDecrypter
Parameters:
objNum - the object number of the containing object
objGen - the generation number of the containing object
inputBasicString - the string to be decrypted
Returns:
the decrypted string
Throws:
PDFParseException - if the named crypt filter does not exist, or if a crypt filter is named when named crypt filters are not supported. Problems due to incorrect passwords are revealed prior to this point.

isOwnerAuthorised

public boolean isOwnerAuthorised()
Description copied from interface: PDFDecrypter
Determine whether the password known by the decrypter indicates that the user is the owner of the document. Can be used, in conjunction with PDFDecrypter.isEncryptionPresent() to determine whether any permissions apply.

Specified by:
isOwnerAuthorised in interface PDFDecrypter
Returns:
whether owner authentication is being used to decrypt the document

isEncryptionPresent

public boolean isEncryptionPresent()
Description copied from interface: PDFDecrypter
Determine whether this actually applies a decryption other than identity decryption.

Specified by:
isEncryptionPresent in interface PDFDecrypter
Returns:
whether encryption is present

isEncryptionPresent

public boolean isEncryptionPresent(java.lang.String cryptFilterName)
Description copied from interface: PDFDecrypter
Determines whether decryption applies for a given crypt filter name

Specified by:
isEncryptionPresent in interface PDFDecrypter
Parameters:
cryptFilterName - the crypt filter name
Returns:
whether the given crypt filter decrypts or not