poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r951048 - in /poi/trunk/src: documentation/content/xdocs/status.xml java/org/apache/poi/poifs/crypt/Decryptor.java
Date Thu, 03 Jun 2010 16:13:38 GMT
Author: nick
Date: Thu Jun  3 16:13:38 2010
New Revision: 951048

URL: http://svn.apache.org/viewvc?rev=951048&view=rev
Log:
Fix bug #49378 - correct 1.6ism

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=951048&r1=951047&r2=951048&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Jun  3 16:13:38 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">49378 - correct 1.6ism</action>
            <action dev="POI-DEVELOPERS" type="add">Parse the HSMF headers chunk if
present, and use it to find Dates in text extraction if needed</action>
            <action dev="POI-DEVELOPERS" type="fix">48494 - detect and support time
formats like HH:MM;HH:MM</action>
            <action dev="POI-DEVELOPERS" type="fix">48494 - have ExcelExtractor make
use of HSSFDataFormatter, so that numbers and dates come out closer to how Excel would render
them</action>

Modified: poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java?rev=951048&r1=951047&r2=951048&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java Thu Jun  3 16:13:38 2010
@@ -16,23 +16,23 @@
 ==================================================================== */
 package org.apache.poi.poifs.crypt;
 
-import org.apache.poi.poifs.filesystem.DocumentInputStream;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.LittleEndian;
-
-import javax.crypto.Cipher;
-import javax.crypto.CipherInputStream;
-import javax.crypto.SecretKey;
-import javax.crypto.spec.SecretKeySpec;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
 import java.security.GeneralSecurityException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Arrays;
 
+import javax.crypto.Cipher;
+import javax.crypto.CipherInputStream;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.poi.poifs.filesystem.DocumentInputStream;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.LittleEndian;
+
 /**
  *  @author Maxim Valyanskiy
  */
@@ -104,7 +104,7 @@ public class Decryptor {
         System.arraycopy(x1, 0, x3, 0, x1.length);
         System.arraycopy(x2, 0, x3, x1.length, x2.length);
 
-        return Arrays.copyOf(x3, requiredKeyLength);
+        return truncateOrPad(x3, requiredKeyLength);
     }
 
     public boolean verifyPassword(String password) throws GeneralSecurityException {
@@ -117,10 +117,26 @@ public class Decryptor {
         MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
         byte[] calcVerifierHash = sha1.digest(verifier);
 
-        byte[] verifierHash = Arrays.copyOf(cipher.doFinal(info.getVerifier().getVerifierHash()),
calcVerifierHash.length);
+        byte[] verifierHash = truncateOrPad(cipher.doFinal(info.getVerifier().getVerifierHash()),
calcVerifierHash.length);
 
         return Arrays.equals(calcVerifierHash, verifierHash);
     }
+    
+    /**
+     * Returns a byte array of the requested length,
+     *  truncated or zero padded as needed.
+     * Behaves like Arrays.copyOf in Java 1.6
+     */
+    private byte[] truncateOrPad(byte[] source, int length) {
+       byte[] result = new byte[length];
+       System.arraycopy(source, 0, result, 0, Math.min(length, source.length));
+       if(length > source.length) {
+          for(int i=source.length; i<length; i++) {
+             result[i] = 0;
+          }
+       }
+       return result;
+    }
 
     private Cipher getCipher() throws GeneralSecurityException {
         byte[] key = generateKey(0);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message