pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1640138 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
Date Mon, 17 Nov 2014 10:42:16 GMT
Author: lehmi
Date: Mon Nov 17 10:42:16 2014
New Revision: 1640138

URL: http://svn.apache.org/r1640138
Log:
PDFBOX-2469: improved decryption handling

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java

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=1640138&r1=1640137&r2=1640138&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
Mon Nov 17 10:42:16 2014
@@ -34,8 +34,10 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.crypto.BadPaddingException;
 import javax.crypto.Cipher;
 import javax.crypto.CipherInputStream;
+import javax.crypto.IllegalBlockSizeException;
 import javax.crypto.NoSuchPaddingException;
 import javax.crypto.SecretKey;
 import javax.crypto.spec.IvParameterSpec;
@@ -326,7 +328,14 @@ public abstract class SecurityHandler
                     byte[] buffer = new byte[256];
                     for (int n = 0; -1 != (n = data.read(buffer));)
                     {
-                        output.write(decryptCipher.update(buffer,0, n ));
+                        if (data.available() > 0)
+                        {
+                            output.write(decryptCipher.update(buffer,0, n ));
+                        }
+                        else
+                        {
+                            output.write(decryptCipher.doFinal(buffer,0, n ));
+                        }
                     }
                 }
                 catch (InvalidKeyException e)
@@ -341,6 +350,14 @@ public abstract class SecurityHandler
                 {
                     throw new IOException(e);
                 }
+                catch (IllegalBlockSizeException e)
+                {
+                    throw new IOException(e);
+                }
+                catch (BadPaddingException e)
+                {
+                    throw new IOException(e);
+                }
             }
             else
             {



Mime
View raw message