You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2014/11/05 08:12:14 UTC
svn commit: r1636806 - in
/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox:
pdfwriter/COSWriter.java pdmodel/encryption/SecurityHandler.java
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.