pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1636806 - in /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox: pdfwriter/COSWriter.java pdmodel/encryption/SecurityHandler.java
Date Wed, 05 Nov 2014 07:12:14 GMT
Author: tilman
Date: Wed Nov  5 07:12:13 2014
New Revision: 1636806

URL: http://svn.apache.org/r1636806
Log:
PDFBOX-2456, PDFBOX-2471: correct decryption for strings and ignore encryption dictionary
when decrypting thanks to Stephen Hendrix

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1636806&r1=1636805&r2=1636806&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Wed
Nov  5 07:12:13 2014
@@ -1400,7 +1400,7 @@ public class COSWriter implements ICOSVi
         {
             if(willEncrypt)
             {
-                document.getSecurityHandler().decryptString(
+                document.getSecurityHandler().encryptString(
                     obj,
                     currentObjectKey.getNumber(),
                     currentObjectKey.getGeneration());

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java?rev=1636806&r1=1636805&r2=1636806&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
Wed Nov  5 07:12:13 2014
@@ -191,9 +191,14 @@ public abstract class SecurityHandler
 
         List<COSObject> allObjects = document.getDocument().getObjects();
         Iterator<COSObject> objectIter = allObjects.iterator();
+        COSDictionary encryptionDict = document.getEncryptionDictionary().getCOSDictionary();
         while (objectIter.hasNext())
         {
-            decryptObject(objectIter.next());
+            COSObject nextObj = objectIter.next();
+            if (nextObj.getObject() != encryptionDict)
+            {
+                decryptObject(nextObj);
+            }
         }
         document.setEncryptionDictionary(null);
     }
@@ -470,6 +475,24 @@ public abstract class SecurityHandler
     }
 
     /**
+     * This will encrypt a string.
+     *
+     * @param string the string to encrypt.
+     * @param objNum The object number.
+     * @param genNum The object generation number.
+     *
+     * @throws IOException If an error occurs writing the new string.
+     */
+    public void encryptString(COSString string, long objNum, long genNum) throws CryptographyException,
IOException
+    {
+        ByteArrayInputStream data = new ByteArrayInputStream(string.getBytes());
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        encryptData(objNum, genNum, data, buffer, false /* decrypt */);
+        string.reset();
+        string.append(buffer.toByteArray());
+    }
+    
+    /**
      * This will decrypt a string.
      *
      * @param string the string to decrypt.



Mime
View raw message