pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1640131 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
Date Mon, 17 Nov 2014 10:20:14 GMT
Author: lehmi
Date: Mon Nov 17 10:20:13 2014
New Revision: 1640131

URL: http://svn.apache.org/r1640131
Log:
PDFBOX-2469: avoid BadPaddingException by not using a CipherInputStream

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
  (contents, props changed)

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=1640131&r1=1640130&r2=1640131&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
Mon Nov 17 10:20:13 2014
@@ -33,7 +33,6 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.crypto.Cipher;
-import javax.crypto.CipherInputStream;
 import javax.crypto.NoSuchPaddingException;
 import javax.crypto.SecretKey;
 import javax.crypto.spec.IvParameterSpec;
@@ -306,26 +305,14 @@ public abstract class SecurityHandler
             try
             {
                 Cipher decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
-
                 SecretKey aesKey = new SecretKeySpec(finalKey, "AES");
-
                 IvParameterSpec ips = new IvParameterSpec(iv);
-
                 decryptCipher.init(decrypt ? Cipher.DECRYPT_MODE : Cipher.ENCRYPT_MODE, aesKey,
ips);
 
-                CipherInputStream cipherStream = new CipherInputStream(data, decryptCipher);
-
-                try
-                {
-                    byte[] buffer = new byte[4096];
-                    for (int n = 0; -1 != (n = cipherStream.read(buffer));)
-                    {
-                        output.write(buffer, 0, n);
-                    }
-                }
-                finally
+                byte[] buffer = new byte[256];
+                for (int n = 0; -1 != (n = data.read(buffer));)
                 {
-                    cipherStream.close();
+                	output.write(decryptCipher.update(buffer,0, n ));
                 }
             }
             catch (InvalidKeyException e)

Propchange: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
------------------------------------------------------------------------------
  Merged /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java:r1640127



Mime
View raw message