org.apache.pdfbox.pdmodel.encryption
Class SecurityHandler

java.lang.Object
  extended by org.apache.pdfbox.pdmodel.encryption.SecurityHandler
Direct Known Subclasses:
PublicKeySecurityHandler, StandardSecurityHandler

public abstract class SecurityHandler
extends Object

This class represents a security handler as described in the PDF specifications. A security handler is responsible of documents protection.

Version:
$Revision: 1.4 $
Author:
Ben Litchfield, Benoit Guillon ([email protected])

Field Summary
protected  AccessPermission currentAccessPermission
          The access permission granted to the current user for the document.
protected  PDDocument document
          The document whose security is handled by this security handler.
protected  byte[] encryptionKey
          The encryption key that will used to encrypt / decrypt.
protected  int keyLength
          The length of the secret key used to encrypt the document.
protected  ARCFour rc4
          The RC4 implementation used for cryptographic functions.
protected  int version
          The value of V field of the Encryption dictionary.
 
Constructor Summary
SecurityHandler()
           
 
Method Summary
abstract  void decryptDocument(PDDocument doc, DecryptionMaterial mat)
          Prepare the document for decryption.
 void decryptStream(COSStream stream, long objNum, long genNum)
          This will decrypt a stream.
 void decryptString(COSString string, long objNum, long genNum)
          This will decrypt a string.
 void encryptData(long objectNumber, long genNumber, InputStream data, OutputStream output)
          Encrypt a set of data.
 AccessPermission getCurrentAccessPermission()
          Returns the access permissions that were computed during document decryption.
 int getKeyLength()
          Getter of the property keyLength.
abstract  void prepareDocumentForEncryption(PDDocument doc)
          Prepare the document for encryption.
protected  void proceedDecryption()
          This method must be called by an implementation of this class to really proceed to decryption.
 void setKeyLength(int keyLen)
          Setter of the property keyLength.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

protected int version
The value of V field of the Encryption dictionary.


keyLength

protected int keyLength
The length of the secret key used to encrypt the document.


encryptionKey

protected byte[] encryptionKey
The encryption key that will used to encrypt / decrypt.


document

protected PDDocument document
The document whose security is handled by this security handler.


rc4

protected ARCFour rc4
The RC4 implementation used for cryptographic functions.


currentAccessPermission

protected AccessPermission currentAccessPermission
The access permission granted to the current user for the document. These permissions are computed during decryption and are in read only mode.

Constructor Detail

SecurityHandler

public SecurityHandler()
Method Detail

prepareDocumentForEncryption

public abstract void prepareDocumentForEncryption(PDDocument doc)
                                           throws CryptographyException,
                                                  IOException
Prepare the document for encryption.

Parameters:
doc - The document that will be encrypted.
Throws:
CryptographyException - If there is an error while preparing.
IOException - If there is an error with the document.

decryptDocument

public abstract void decryptDocument(PDDocument doc,
                                     DecryptionMaterial mat)
                              throws CryptographyException,
                                     IOException
Prepare the document for decryption.

Parameters:
doc - The document to decrypt.
mat - Information required to decrypt the document.
Throws:
CryptographyException - If there is an error while preparing.
IOException - If there is an error with the document.

proceedDecryption

protected void proceedDecryption()
                          throws IOException,
                                 CryptographyException
This method must be called by an implementation of this class to really proceed to decryption.

Throws:
IOException - If there is an error in the decryption.
CryptographyException - If there is an error in the decryption.

encryptData

public void encryptData(long objectNumber,
                        long genNumber,
                        InputStream data,
                        OutputStream output)
                 throws CryptographyException,
                        IOException
Encrypt a set of data.

Parameters:
objectNumber - The data object number.
genNumber - The data generation number.
data - The data to encrypt.
output - The output to write the encrypted data to.
Throws:
CryptographyException - If there is an error during the encryption.
IOException - If there is an error reading the data.

decryptStream

public void decryptStream(COSStream stream,
                          long objNum,
                          long genNum)
                   throws CryptographyException,
                          IOException
This will decrypt a stream.

Parameters:
stream - The stream to decrypt.
objNum - The object number.
genNum - The object generation number.
Throws:
CryptographyException - If there is an error getting the stream.
IOException - If there is an error getting the stream data.

decryptString

public void decryptString(COSString string,
                          long objNum,
                          long genNum)
                   throws CryptographyException,
                          IOException
This will decrypt a string.

Parameters:
string - the string to decrypt.
objNum - The object number.
genNum - The object generation number.
Throws:
CryptographyException - If an error occurs during decryption.
IOException - If an error occurs writing the new string.

getKeyLength

public int getKeyLength()
Getter of the property keyLength.

Returns:
Returns the keyLength.

setKeyLength

public void setKeyLength(int keyLen)
Setter of the property keyLength.

Parameters:
keyLen - The keyLength to set.

getCurrentAccessPermission

public AccessPermission getCurrentAccessPermission()
Returns the access permissions that were computed during document decryption. The returned object is in read only mode.

Returns:
the access permissions or null if the document was not decrypted.


Copyright © 2002-2010 The Apache Software Foundation. All Rights Reserved.