Index: pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>ISO-8859-1
===================================================================
--- pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java	(revision 1636387)
+++ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java	(revision )
@@ -163,8 +163,11 @@
         Iterator<COSObject> objectIter = allObjects.iterator();
         while (objectIter.hasNext())
         {
-            decryptObject(objectIter.next());
+            COSObject nextObj = objectIter.next();
+            if (nextObj.getObject() != document.getEncryption().getCOSDictionary()) {
+                decryptObject(nextObj);
-        }
+            }
+        }
         document.setEncryptionDictionary(null);
     }
 
@@ -484,6 +487,25 @@
         ByteArrayInputStream data = new ByteArrayInputStream(string.getBytes());
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         encryptData(objNum, genNum, data, buffer, true /* decrypt */);
+        string.reset();
+        string.append(buffer.toByteArray());
+    }
+
+
+    /**
+     * 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 IOException
+    {
+        ByteArrayInputStream data = new ByteArrayInputStream(string.getBytes());
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        encryptData(objNum, genNum, data, buffer, false /* encrypt */);
         string.reset();
         string.append(buffer.toByteArray());
     }
Index: pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>ISO-8859-1
===================================================================
--- pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java	(revision 1636387)
+++ pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java	(revision )
@@ -1262,7 +1262,7 @@
     {
         if(willEncrypt)
         {
-            document.getEncryption().getSecurityHandler().decryptString(
+            document.getEncryption().getSecurityHandler().encryptString(
                     obj,
                     currentObjectKey.getNumber(),
                     currentObjectKey.getGeneration());
Index: pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>ISO-8859-1
===================================================================
--- pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java	(revision 1636387)
+++ pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java	(revision )
@@ -113,7 +113,7 @@
      */
     public void testProtection() throws Exception
     {
-        byte[] inputFileAsByteArray = getFileResourceAsByteArray("test.pdf");
+        byte[] inputFileAsByteArray = getFileResourceAsByteArray("Acroform-PDFBOX-2333.pdf");
         int sizePriorToEncryption = inputFileAsByteArray.length;
 
         PDDocument document = PDDocument.load(new ByteArrayInputStream(inputFileAsByteArray));
@@ -125,8 +125,8 @@
         //TODO
         // 1) check permissions
         // 2) 256 key length
-        //document = PDDocument.load(new ByteArrayInputStream(inputFileAsByteArray));
-        //testSymmEncrForKeySize(256, sizePriorToEncryption, document, PASSWORD, permission1);
+        document = PDDocument.load(new ByteArrayInputStream(inputFileAsByteArray));
+        testSymmEncrForKeySize(256, sizePriorToEncryption, document, PASSWORD, permission1);
     }
 
     /**
