You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2014/03/13 23:36:33 UTC

svn commit: r1577354 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: pdfparser/ pdfwriter/ pdmodel/ pdmodel/encryption/

Author: jahewson
Date: Thu Mar 13 22:36:33 2014
New Revision: 1577354

URL: http://svn.apache.org/r1577354
Log:
PDFBOX-1986: Move SecurityHandler to PDEncryptionDictionary

Added:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java
      - copied, changed from r1576871, pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1577354&r1=1577353&r2=1577354&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Thu Mar 13 22:36:33 2014
@@ -56,14 +56,12 @@ import org.apache.pdfbox.io.RandomAccess
 import org.apache.pdfbox.io.RandomAccessBuffer;
 import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
 import org.apache.pdfbox.pdfparser.XrefTrailerResolver.XRefType;
-import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
 import org.apache.pdfbox.pdmodel.encryption.DecryptionMaterial;
-import org.apache.pdfbox.pdmodel.encryption.PDEncryptionDictionary;
+import org.apache.pdfbox.pdmodel.encryption.PDEncryption;
 import org.apache.pdfbox.pdmodel.encryption.PublicKeyDecryptionMaterial;
 import org.apache.pdfbox.pdmodel.encryption.SecurityHandler;
-import org.apache.pdfbox.pdmodel.encryption.SecurityHandlerFactory;
 import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial;
 import org.apache.pdfbox.persistence.util.COSObjectKey;
 
@@ -413,7 +411,7 @@ public class NonSequentialPDFParser exte
             }
             try
             {
-                PDEncryptionDictionary encParameters = new PDEncryptionDictionary(document.getEncryptionDictionary());
+                PDEncryption encryption = new PDEncryption(document.getEncryptionDictionary());
 
                 DecryptionMaterial decryptionMaterial;
                 if (keyStoreFilename != null)
@@ -428,12 +426,8 @@ public class NonSequentialPDFParser exte
                     decryptionMaterial = new StandardDecryptionMaterial(password);
                 }
 
-                securityHandler = SecurityHandlerFactory.INSTANCE.newSecurityHandler(encParameters.getFilter());
-                if (securityHandler == null)
-                {
-                    throw new IOException("No security handler for filter " + encParameters.getFilter());
-                }
-                securityHandler.prepareForDecryption(encParameters, document.getDocumentID(), decryptionMaterial);
+                securityHandler = encryption.getSecurityHandler();
+                securityHandler.prepareForDecryption(encryption, document.getDocumentID(), decryptionMaterial);
 
                 AccessPermission permission = securityHandler.getCurrentAccessPermission();
                 if (!permission.canExtractContent())
@@ -842,40 +836,6 @@ public class NonSequentialPDFParser exte
 
     // ------------------------------------------------------------------------
     /**
-     * Returns security handler of the document or <code>null</code> if document
-     * is not encrypted or {@link #parse()} wasn't called before.
-     * 
-     * @return the security handler.
-     */
-    public SecurityHandler getSecurityHandler()
-    {
-        return securityHandler;
-    }
-
-    // ------------------------------------------------------------------------
-    /**
-     * This will get the PD document that was parsed. When you are done with
-     * this document you must call close() on it to release resources.
-     * 
-     * Overwriting super method was necessary in order to set security handler.
-     * 
-     * @return The document at the PD layer.
-     * 
-     * @throws IOException If there is an error getting the document.
-     */
-    @Override
-    public PDDocument getPDDocument() throws IOException
-    {
-        PDDocument pdDocument = super.getPDDocument();
-        if (securityHandler != null)
-        {
-            pdDocument.setSecurityHandler(securityHandler);
-        }
-        return pdDocument;
-    }
-
-    // ------------------------------------------------------------------------
-    /**
      * Returns the number of pages in a document.
      * 
      * @return the number of pages.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1577354&r1=1577353&r2=1577354&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Thu Mar 13 22:36:33 2014
@@ -1149,8 +1149,9 @@ public class COSWriter implements ICOSVi
     {
         if (willEncrypt)
         {
-            document.getSecurityHandler().encryptStream(obj, currentObjectKey.getNumber(),
-                                                        currentObjectKey.getGeneration());
+            document.getEncryption().getSecurityHandler()
+                    .encryptStream(obj, currentObjectKey.getNumber(),
+                            currentObjectKey.getGeneration());
         }
 
         COSObject lengthObject = null;
@@ -1215,7 +1216,7 @@ public class COSWriter implements ICOSVi
     {
         if(willEncrypt)
         {
-            document.getSecurityHandler().decryptString(
+            document.getEncryption().getSecurityHandler().decryptString(
                     obj,
                     currentObjectKey.getNumber(),
                     currentObjectKey.getGeneration());
@@ -1267,11 +1268,18 @@ public class COSWriter implements ICOSVi
         }
         else
         {
-            SecurityHandler securityHandler = document.getSecurityHandler();
-            if(securityHandler != null)
+            if (document.isEncrypted())
             {
-                securityHandler.prepareDocumentForEncryption(document);
-                willEncrypt = true;
+                SecurityHandler securityHandler = document.getEncryption().getSecurityHandler();
+                if(securityHandler != null)
+                {
+                    securityHandler.prepareDocumentForEncryption(document);
+                    willEncrypt = true;
+                }
+                else
+                {
+                    willEncrypt = false;
+                }
             }
             else
             {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1577354&r1=1577353&r2=1577354&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Thu Mar 13 22:36:33 2014
@@ -50,7 +50,7 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
 import org.apache.pdfbox.pdmodel.encryption.DecryptionMaterial;
 import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
-import org.apache.pdfbox.pdmodel.encryption.PDEncryptionDictionary;
+import org.apache.pdfbox.pdmodel.encryption.PDEncryption;
 import org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy;
 import org.apache.pdfbox.pdmodel.encryption.SecurityHandler;
 import org.apache.pdfbox.pdmodel.encryption.SecurityHandlerFactory;
@@ -81,12 +81,9 @@ public class PDDocument implements Close
     private PDDocumentInformation documentInformation;
     private PDDocumentCatalog documentCatalog;
 
-    // the encParameters will be cached here. When the document is decrypted then
+    // the encryption will be cached here. When the document is decrypted then
     // the COSDocument will not have an "Encrypt" dictionary anymore and this object must be used
-    private PDEncryptionDictionary encParameters;
-
-    // the security handler used to decrypt / encrypt the document
-    private SecurityHandler securityHandler;
+    private PDEncryption encryption;
 
     // associates object ids with a page number. Used to determine the page number for bookmarks
     // (or page numbers for anything else for which you have an object id for that matter)
@@ -745,37 +742,46 @@ public class PDDocument implements Close
     }
 
     /**
+     * @deprecated Use {@link #getEncryption()} instead.
+     *
+     * @return The encryption dictionary(most likely a PDStandardEncryption object)
+     */
+    @Deprecated
+    public PDEncryption getEncryptionDictionary()
+    {
+        return getEncryption();
+    }
+
+    /**
      * This will get the encryption dictionary for this document. This will still return the parameters if the document
-     * was decrypted. If the document was never encrypted then this will return null. As the encryption architecture in
-     * PDF documents is plugable this returns an abstract class, but the only supported subclass at this time is a
+     * was decrypted. As the encryption architecture in PDF documents is plugable this returns an abstract class,
+     * but the only supported subclass at this time is a
      * PDStandardEncryption object.
-     * 
+     *
      * @return The encryption dictionary(most likely a PDStandardEncryption object)
-     * 
-     * @throws IOException If there is an error determining which security handler to use.
      */
-    public PDEncryptionDictionary getEncryptionDictionary() throws IOException
+    public PDEncryption getEncryption()
     {
-        if (encParameters == null)
+        if (encryption == null)
         {
             if (isEncrypted())
             {
-                encParameters = new PDEncryptionDictionary(document.getEncryptionDictionary());
+                encryption = new PDEncryption(document.getEncryptionDictionary());
             }
         }
-        return encParameters;
+        return encryption;
     }
 
     /**
      * This will set the encryption dictionary for this document.
      * 
-     * @param encDictionary The encryption dictionary(most likely a PDStandardEncryption object)
+     * @param encryption The encryption dictionary(most likely a PDStandardEncryption object)
      * 
      * @throws IOException If there is an error determining which security handler to use.
      */
-    public void setEncryptionDictionary(PDEncryptionDictionary encDictionary) throws IOException
+    public void setEncryptionDictionary(PDEncryption encryption) throws IOException
     {
-        encParameters = encDictionary;
+        this.encryption = encryption;
     }
 
     /**
@@ -864,11 +870,15 @@ public class PDDocument implements Close
      * @throws IOException If there is an error accessing the data.
      */
     @Deprecated
-    public void encrypt(String ownerPassword, String userPassword)
-            throws IOException
+    public void encrypt(String ownerPassword, String userPassword) throws IOException
     {
-        securityHandler = new StandardSecurityHandler(
-                new StandardProtectionPolicy(ownerPassword, userPassword, new AccessPermission()));
+        if (!isEncrypted())
+        {
+            encryption = new PDEncryption();
+        }
+
+        getEncryption().setSecurityHandler(new StandardSecurityHandler(
+                new StandardProtectionPolicy(ownerPassword, userPassword, new AccessPermission())));
     }
 
     /**
@@ -1276,13 +1286,12 @@ public class PDDocument implements Close
     {
         documentCatalog = null;
         documentInformation = null;
-        encParameters = null;
+        encryption = null;
         if (pageMap != null)
         {
             pageMap.clear();
             pageMap = null;
         }
-        securityHandler = null;
         if (document != null)
         {
             document.close();
@@ -1306,11 +1315,18 @@ public class PDDocument implements Close
      */
     public void protect(ProtectionPolicy policy) throws IOException
     {
-        securityHandler = SecurityHandlerFactory.INSTANCE.newSecurityHandlerForPolicy(policy);
+        if (!isEncrypted())
+        {
+            encryption = new PDEncryption();
+        }
+
+        SecurityHandler securityHandler = SecurityHandlerFactory.INSTANCE.newSecurityHandlerForPolicy(policy);
         if (securityHandler == null)
         {
             throw new IOException("No security handler for policy " + policy);
         }
+
+        getEncryption().setSecurityHandler(securityHandler);
     }
 
     /**
@@ -1325,22 +1341,15 @@ public class PDDocument implements Close
      */
     public void openProtection(DecryptionMaterial decryptionMaterial) throws IOException
     {
-        PDEncryptionDictionary encryption = getEncryptionDictionary();
-        if (encryption.getFilter() != null)
+        if (isEncrypted())
         {
-            securityHandler = SecurityHandlerFactory.INSTANCE.newSecurityHandler(encryption.getFilter());
-            if (securityHandler == null)
-            {
-                throw new IOException("No security handler for filter " + encryption.getFilter());
-            }
-
-            securityHandler.decryptDocument(this, decryptionMaterial);
+            getEncryption().getSecurityHandler().decryptDocument(this, decryptionMaterial);
             document.dereferenceObjectStreams();
             document.setEncryptionDictionary(null);
         }
         else
         {
-            throw new IOException("The document is not encrypted");
+            throw new IOException("Document is not encrypted");
         }
     }
 
@@ -1352,41 +1361,71 @@ public class PDDocument implements Close
      * 
      * @return the access permissions for the current user on the document.
      */
-
     public AccessPermission getCurrentAccessPermission()
     {
-        if (securityHandler == null)
+        if (isEncrypted() && getEncryption().hasSecurityHandler())
+        {
+            try
+            {
+                return getEncryption().getSecurityHandler().getCurrentAccessPermission();
+            }
+            catch (IOException e)
+            {
+                // will never happen because we checked hasSecurityHandler() first
+                throw new RuntimeException(e);
+            }
+        }
+        else
         {
             return AccessPermission.getOwnerAccessPermission();
         }
-        return securityHandler.getCurrentAccessPermission();
     }
 
     /**
      * Get the security handler that is used for document encryption.
-     * 
+     *
+     * @deprecated Use {@link #getEncryption()}.
+     * {@link org.apache.pdfbox.pdmodel.encryption.PDEncryption#getSecurityHandler()}
+     *
      * @return The handler used to encrypt/decrypt the document.
      */
+    @Deprecated
     public SecurityHandler getSecurityHandler()
     {
-        return securityHandler;
+        if (isEncrypted() && getEncryption().hasSecurityHandler())
+        {
+            try
+            {
+                return getEncryption().getSecurityHandler();
+            }
+            catch (IOException e)
+            {
+                // will never happen because we checked hasSecurityHandler() first
+                throw new RuntimeException(e);
+            }
+        }
+        else
+        {
+            return null;
+        }
     }
 
     /**
-     * Sets security handler if none is set already.
-     * 
-     * @param secHandler security handler to be assigned to document
-     * @return <code>true</code> if security handler was set, <code>false</code> otherwise (a security handler was
-     *         already set)
+     * @deprecated Use protection policies instead.
+     *
+     * @param securityHandler security handler to be assigned to document
+     * @return true if security handler was set
      */
-    public boolean setSecurityHandler(SecurityHandler secHandler)
+    @Deprecated
+    public boolean setSecurityHandler(SecurityHandler securityHandler)
     {
-        if (securityHandler == null)
+        if (isEncrypted())
         {
-            securityHandler = secHandler;
-            return true;
+            return false;
         }
-        return false;
+        encryption = new PDEncryption();
+        getEncryption().setSecurityHandler(securityHandler);
+        return true;
     }
 
     /**

Copied: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java (from r1576871, pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java)
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java?p2=pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java&p1=pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java&r1=1576871&r2=1577354&rev=1577354&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java Thu Mar 13 22:36:33 2014
@@ -34,12 +34,10 @@ import org.apache.pdfbox.cos.COSString;
  * The available fields are the ones who are involved by standard security handler
  * and public key security handler.
  *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @author Benoit Guillon (benoit.guillon@snv.jussieu.fr)
- *
- * @version $Revision: 1.7 $
+ * @author Ben Litchfield
+ * @author Benoit Guillon
  */
-public class PDEncryptionDictionary
+public class PDEncryption
 {
     /**
      * See PDF Reference 1.4 Table 3.13.
@@ -77,26 +75,58 @@ public class PDEncryptionDictionary
      */
     public static final int DEFAULT_VERSION = VERSION0_UNDOCUMENTED_UNSUPPORTED;
 
-    /**
-     * COS encryption dictionary.
-     */
-    protected COSDictionary encryptionDictionary = null;
+    private COSDictionary dictionary;
+    private SecurityHandler securityHandler;
 
     /**
      * creates a new empty encryption dictionary.
      */
-    public PDEncryptionDictionary()
+    public PDEncryption()
     {
-        encryptionDictionary = new COSDictionary();
+        dictionary = new COSDictionary();
     }
 
     /**
      * creates a new encryption dictionary from the low level dictionary provided.
-     * @param d the low level dictionary that will be managed by the newly created object
+     * @param dictionary a COS encryption dictionary
+     */
+    public PDEncryption(COSDictionary dictionary)
+    {
+        this.dictionary = dictionary;
+        securityHandler = SecurityHandlerFactory.INSTANCE.newSecurityHandler(getFilter());
+    }
+
+    /**
+     * Returns the security handler specified in the dictionary's Filter entry.
+     * @return a security handler instance
+     * @throws IOException if there is no security handler available which matches the Filter
+     */
+    public SecurityHandler getSecurityHandler() throws IOException
+    {
+        if (securityHandler == null)
+        {
+            throw new IOException("No security handler for filter " + getFilter());
+        }
+        return securityHandler;
+    }
+
+    /**
+     * Sets the security handler used in this encryption dictionary
+     * @param securityHandler new security handler
+     */
+    public void setSecurityHandler(SecurityHandler securityHandler)
+    {
+        this.securityHandler = securityHandler;
+        // TODO set Filter (currently this is done by the security handlers)
+    }
+
+    /**
+     * Returns true if the security handler specified in the dictionary's Filter is available.
+     * @return true if the security handler is available
      */
-    public PDEncryptionDictionary(COSDictionary d)
+    public boolean hasSecurityHandler()
     {
-        encryptionDictionary = d;
+        return securityHandler == null;
     }
 
     /**
@@ -106,7 +136,7 @@ public class PDEncryptionDictionary
      */
     public COSDictionary getCOSDictionary()
     {
-        return encryptionDictionary;
+        return dictionary;
     }
 
     /**
@@ -116,7 +146,7 @@ public class PDEncryptionDictionary
      */
     public void setFilter(String filter)
     {
-        encryptionDictionary.setItem( COSName.FILTER, COSName.getPDFName( filter ) );
+        dictionary.setItem(COSName.FILTER, COSName.getPDFName(filter));
     }
 
     /**
@@ -126,7 +156,7 @@ public class PDEncryptionDictionary
      */
     public String getFilter()
     {
-        return encryptionDictionary.getNameAsString( COSName.FILTER );
+        return dictionary.getNameAsString( COSName.FILTER );
     }
 
     /**
@@ -136,7 +166,7 @@ public class PDEncryptionDictionary
      */
     public String getSubFilter()
     {
-        return encryptionDictionary.getNameAsString( COSName.SUB_FILTER );
+        return dictionary.getNameAsString( COSName.SUB_FILTER );
     }
 
     /**
@@ -146,7 +176,7 @@ public class PDEncryptionDictionary
      */
     public void setSubFilter(String subfilter)
     {
-        encryptionDictionary.setName( COSName.SUB_FILTER, subfilter );
+        dictionary.setName(COSName.SUB_FILTER, subfilter);
     }
 
     /**
@@ -159,7 +189,7 @@ public class PDEncryptionDictionary
      */
     public void setVersion(int version)
     {
-        encryptionDictionary.setInt( COSName.V, version );
+        dictionary.setInt(COSName.V, version);
     }
 
     /**
@@ -170,7 +200,7 @@ public class PDEncryptionDictionary
      */
     public int getVersion()
     {
-        return encryptionDictionary.getInt( COSName.V, 0 );
+        return dictionary.getInt( COSName.V, 0 );
     }
 
     /**
@@ -180,7 +210,7 @@ public class PDEncryptionDictionary
      */
     public void setLength(int length)
     {
-        encryptionDictionary.setInt(COSName.LENGTH, length);
+        dictionary.setInt(COSName.LENGTH, length);
     }
 
     /**
@@ -191,7 +221,7 @@ public class PDEncryptionDictionary
      */
     public int getLength()
     {
-        return encryptionDictionary.getInt( COSName.LENGTH, 40 );
+        return dictionary.getInt( COSName.LENGTH, 40 );
     }
 
     /**
@@ -205,7 +235,7 @@ public class PDEncryptionDictionary
      */
     public void setRevision(int revision)
     {
-        encryptionDictionary.setInt( COSName.R, revision );
+        dictionary.setInt(COSName.R, revision);
     }
 
     /**
@@ -216,7 +246,7 @@ public class PDEncryptionDictionary
      */
     public int getRevision()
     {
-        return encryptionDictionary.getInt( COSName.R, DEFAULT_VERSION );
+        return dictionary.getInt( COSName.R, DEFAULT_VERSION );
     }
 
      /**
@@ -230,7 +260,7 @@ public class PDEncryptionDictionary
     {
         COSString owner = new COSString();
         owner.append( o );
-        encryptionDictionary.setItem( COSName.O, owner );
+        dictionary.setItem(COSName.O, owner);
     }
 
     /**
@@ -243,7 +273,7 @@ public class PDEncryptionDictionary
     public byte[] getOwnerKey() throws IOException
     {
         byte[] o = null;
-        COSString owner = (COSString)encryptionDictionary.getDictionaryObject( COSName.O );
+        COSString owner = (COSString) dictionary.getDictionaryObject( COSName.O );
         if( owner != null )
         {
             o = owner.getBytes();
@@ -262,7 +292,7 @@ public class PDEncryptionDictionary
     {
         COSString user = new COSString();
         user.append( u );
-        encryptionDictionary.setItem( COSName.U, user );
+        dictionary.setItem(COSName.U, user);
     }
 
     /**
@@ -275,7 +305,7 @@ public class PDEncryptionDictionary
     public byte[] getUserKey() throws IOException
     {
         byte[] u = null;
-        COSString user = (COSString)encryptionDictionary.getDictionaryObject( COSName.U );
+        COSString user = (COSString) dictionary.getDictionaryObject( COSName.U );
         if( user != null )
         {
             u = user.getBytes();
@@ -290,7 +320,7 @@ public class PDEncryptionDictionary
      */
     public void setPermissions(int permissions)
     {
-        encryptionDictionary.setInt( COSName.P, permissions );
+        dictionary.setInt(COSName.P, permissions);
     }
 
     /**
@@ -300,7 +330,7 @@ public class PDEncryptionDictionary
      */
     public int getPermissions()
     {
-        return encryptionDictionary.getInt( COSName.P, 0 );
+        return dictionary.getInt( COSName.P, 0 );
     }
 
     /**
@@ -313,7 +343,7 @@ public class PDEncryptionDictionary
         // default is true (see 7.6.3.2 Standard Encryption Dictionary PDF 32000-1:2008)
         boolean encryptMetaData = true;
         
-        COSBase value = encryptionDictionary.getDictionaryObject(COSName.ENCRYPT_META_DATA);
+        COSBase value = dictionary.getDictionaryObject(COSName.ENCRYPT_META_DATA);
         
         if (value instanceof COSBoolean) {
             encryptMetaData = ((COSBoolean)value).getValue();
@@ -338,7 +368,7 @@ public class PDEncryptionDictionary
             recip.setForceLiteralForm(true);
             array.add(recip);
         }
-        encryptionDictionary.setItem(COSName.RECIPIENTS, array);
+        dictionary.setItem(COSName.RECIPIENTS, array);
     }
 
     /**
@@ -348,7 +378,7 @@ public class PDEncryptionDictionary
      */
     public int getRecipientsLength()
     {
-        COSArray array = (COSArray)encryptionDictionary.getItem(COSName.RECIPIENTS);
+        COSArray array = (COSArray) dictionary.getItem(COSName.RECIPIENTS);
         return array.size();
     }
 
@@ -361,7 +391,7 @@ public class PDEncryptionDictionary
      */
     public COSString getRecipientStringAt(int i)
     {
-        COSArray array = (COSArray)encryptionDictionary.getItem(COSName.RECIPIENTS);
+        COSArray array = (COSArray) dictionary.getItem(COSName.RECIPIENTS);
         return (COSString)array.get(i);
     }
     
@@ -384,7 +414,7 @@ public class PDEncryptionDictionary
      */
     public PDCryptFilterDictionary getCryptFilterDictionary(COSName cryptFilterName) 
     {
-        COSDictionary cryptFilterDictionary = (COSDictionary)encryptionDictionary.getDictionaryObject( COSName.CF );
+        COSDictionary cryptFilterDictionary = (COSDictionary) dictionary.getDictionaryObject( COSName.CF );
         if (cryptFilterDictionary != null)
         {
             COSDictionary stdCryptFilterDictionary = (COSDictionary)cryptFilterDictionary.getDictionaryObject(cryptFilterName);
@@ -404,7 +434,7 @@ public class PDEncryptionDictionary
      */
     public COSName getStreamFilterName() 
     {
-        COSName stmF = (COSName)encryptionDictionary.getDictionaryObject( COSName.STM_F );
+        COSName stmF = (COSName) dictionary.getDictionaryObject( COSName.STM_F );
         if (stmF == null)
         {
             stmF = COSName.IDENTITY;
@@ -420,7 +450,7 @@ public class PDEncryptionDictionary
      */
     public COSName getStringFilterName() 
     {
-        COSName strF = (COSName)encryptionDictionary.getDictionaryObject( COSName.STR_F );
+        COSName strF = (COSName) dictionary.getDictionaryObject( COSName.STR_F );
         if (strF == null)
         {
             strF = COSName.IDENTITY;

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java?rev=1577354&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryptionDictionary.java Thu Mar 13 22:36:33 2014
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.pdmodel.encryption;
+
+import org.apache.pdfbox.cos.COSDictionary;
+
+/**
+ * @deprecated Use {@link PDEncryption} instead
+ */
+@Deprecated
+public class PDEncryptionDictionary extends PDEncryption
+{
+    /**
+     * @deprecated Use {@link PDEncryption()} instead
+     */
+    public PDEncryptionDictionary()
+    {
+        super();
+    }
+
+    /**
+     * @deprecated Use {@link PDEncryption(COSDictionary)} instead
+     * @param dictionary a COS encryption dictionary
+     */
+    public PDEncryptionDictionary(COSDictionary dictionary)
+    {
+        super(dictionary);
+    }
+}

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java?rev=1577354&r1=1577353&r2=1577354&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java Thu Mar 13 22:36:33 2014
@@ -110,7 +110,7 @@ public final class PublicKeySecurityHand
     {
         this.document = doc;
 
-        PDEncryptionDictionary dictionary = doc.getEncryptionDictionary();
+        PDEncryption dictionary = doc.getEncryption();
 
         prepareForDecryption( dictionary, doc.getDocument().getDocumentID(),
         											decryptionMaterial );
@@ -124,19 +124,19 @@ public final class PublicKeySecurityHand
      * If {@link #decryptDocument(PDDocument, DecryptionMaterial)} is used, this method is
      * called from there. Only if decryption of single objects is needed this should be called instead.
      *
-     * @param encDictionary  encryption dictionary, can be retrieved via {@link PDDocument#getEncryptionDictionary()}
+     * @param encryption  encryption dictionary, can be retrieved via {@link PDDocument#getEncryption()}
      * @param documentIDArray  document id which is returned via {@link org.apache.pdfbox.cos.COSDocument#getDocumentID()} (not used by this handler)
      * @param decryptionMaterial Information used to decrypt the document.
      *
      * @throws IOException If there is an error accessing data.
      */
-    public void prepareForDecryption(PDEncryptionDictionary encDictionary, COSArray documentIDArray,
+    public void prepareForDecryption(PDEncryption encryption, COSArray documentIDArray,
                                      DecryptionMaterial decryptionMaterial)
                                      throws IOException
     {
-	      if(encDictionary.getLength() != 0)
+	      if(encryption.getLength() != 0)
 	      {
-	          this.keyLength = encDictionary.getLength();
+	          this.keyLength = encryption.getLength();
 	      }
 	
 	      if(!(decryptionMaterial instanceof PublicKeyDecryptionMaterial))
@@ -156,13 +156,13 @@ public final class PublicKeySecurityHand
 	          byte[] envelopedData = null;
 	
 	          // the bytes of each recipient in the recipients array
-	          byte[][] recipientFieldsBytes = new byte[encDictionary.getRecipientsLength()][];
+	          byte[][] recipientFieldsBytes = new byte[encryption.getRecipientsLength()][];
 	
 	          int recipientFieldsLength = 0;
 	
-	          for(int i=0; i<encDictionary.getRecipientsLength(); i++)
+	          for(int i=0; i< encryption.getRecipientsLength(); i++)
 	          {
-	              COSString recipientFieldString = encDictionary.getRecipientStringAt(i);
+	              COSString recipientFieldString = encryption.getRecipientStringAt(i);
 	              byte[] recipientBytes = recipientFieldString.getBytes();
 	              CMSEnvelopedData data = new CMSEnvelopedData(recipientBytes);
 	              Iterator recipCertificatesIt = data.getRecipientInfos().getRecipients().iterator();
@@ -250,10 +250,10 @@ public final class PublicKeySecurityHand
         {
             Security.addProvider(new BouncyCastleProvider());
 
-            PDEncryptionDictionary dictionary = doc.getEncryptionDictionary();
+            PDEncryption dictionary = doc.getEncryption();
             if (dictionary == null) 
             {
-                dictionary = new PDEncryptionDictionary();
+                dictionary = new PDEncryption();
             }
 
             dictionary.setFilter(FILTER);
@@ -353,8 +353,7 @@ public final class PublicKeySecurityHand
             System.arraycopy(mdResult, 0, this.encryptionKey, 0, this.keyLength/8);
 
             doc.setEncryptionDictionary(dictionary);
-            doc.getDocument().setEncryptionDictionary(dictionary.encryptionDictionary);
-
+            doc.getDocument().setEncryptionDictionary(dictionary.getCOSDictionary());
         }
         catch(GeneralSecurityException e)
         {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java?rev=1577354&r1=1577353&r2=1577354&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java Thu Mar 13 22:36:33 2014
@@ -104,13 +104,13 @@ public abstract class SecurityHandler
      * If {@link #decryptDocument(PDDocument, DecryptionMaterial)} is used, this method is
      * called from there. Only if decryption of single objects is needed this should be called instead.
      *
-     * @param encDictionary  encryption dictionary, can be retrieved via {@link PDDocument#getEncryptionDictionary()}
+     * @param encryption  encryption dictionary, can be retrieved via {@link PDDocument#getEncryption()}
      * @param documentIDArray  document id which is returned via {@link COSDocument#getDocumentID()}
      * @param decryptionMaterial Information used to decrypt the document.
      *
      * @throws IOException If there is an error accessing data.
      */
-    public abstract void prepareForDecryption(PDEncryptionDictionary encDictionary, COSArray documentIDArray,
+    public abstract void prepareForDecryption(PDEncryption encryption, COSArray documentIDArray,
             DecryptionMaterial decryptionMaterial) throws IOException;
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java?rev=1577354&r1=1577353&r2=1577354&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java Thu Mar 13 22:36:33 2014
@@ -128,7 +128,7 @@ public final class StandardSecurityHandl
     {
         document = doc;
 
-        PDEncryptionDictionary dictionary = document.getEncryptionDictionary();
+        PDEncryption dictionary = document.getEncryption();
         COSArray documentIDArray = document.getDocument().getDocumentID();
         
         prepareForDecryption(dictionary, documentIDArray, decryptionMaterial);
@@ -142,13 +142,13 @@ public final class StandardSecurityHandl
      * Called from {@link #decryptDocument(PDDocument, DecryptionMaterial)}.
      * Only if decryption of single objects is needed this should be called instead.
      *
-     * @param encDictionary  encryption dictionary
+     * @param encryption  encryption dictionary
      * @param documentIDArray  document id
      * @param decryptionMaterial Information used to decrypt the document.
      *
      * @throws IOException If there is an error accessing data.
      */
-    public void prepareForDecryption(PDEncryptionDictionary encDictionary, COSArray documentIDArray,
+    public void prepareForDecryption(PDEncryption encryption, COSArray documentIDArray,
                                      DecryptionMaterial decryptionMaterial)
                                      throws IOException
     {
@@ -165,9 +165,9 @@ public final class StandardSecurityHandl
             password = "";
         }
 
-        int dicPermissions = encDictionary.getPermissions();
-        int dicRevision = encDictionary.getRevision();
-        int dicLength = encDictionary.getLength()/8;
+        int dicPermissions = encryption.getPermissions();
+        int dicRevision = encryption.getRevision();
+        int dicLength = encryption.getLength()/8;
 
         //some documents may have not document id, see
         //test\encryption\encrypted_doc_no_id.pdf
@@ -183,10 +183,10 @@ public final class StandardSecurityHandl
         }
 
         // we need to know whether the meta data was encrypted for password calculation
-        boolean encryptMetadata = encDictionary.isEncryptMetaData();
+        boolean encryptMetadata = encryption.isEncryptMetaData();
         
-        byte[] userKey = encDictionary.getUserKey();
-        byte[] ownerKey = encDictionary.getOwnerKey();
+        byte[] userKey = encryption.getUserKey();
+        byte[] ownerKey = encryption.getOwnerKey();
 
         if( isUserPassword(password.getBytes("ISO-8859-1"), userKey, ownerKey,
                            dicPermissions, documentIDBytes, dicRevision,
@@ -227,7 +227,7 @@ public final class StandardSecurityHandl
 
         // detect whether AES encryption is used. This assumes that the encryption algo is 
         // stored in the PDCryptFilterDictionary
-        PDCryptFilterDictionary stdCryptFilterDictionary =  encDictionary.getStdCryptFilterDictionary();
+        PDCryptFilterDictionary stdCryptFilterDictionary = encryption.getStdCryptFilterDictionary();
 
         if (stdCryptFilterDictionary != null)
         {
@@ -249,10 +249,10 @@ public final class StandardSecurityHandl
     public void prepareDocumentForEncryption(PDDocument doc) throws IOException
     {
         document = doc;
-        PDEncryptionDictionary encryptionDictionary = document.getEncryptionDictionary();
+        PDEncryption encryptionDictionary = document.getEncryption();
         if(encryptionDictionary == null)
         {
-            encryptionDictionary = new PDEncryptionDictionary();
+            encryptionDictionary = new PDEncryption();
         }
         version = computeVersionNumber();
         revision = computeRevisionNumber();