poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r951016 - /poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java
Date Thu, 03 Jun 2010 14:58:02 GMT
Author: nick
Date: Thu Jun  3 14:58:02 2010
New Revision: 951016

URL: http://svn.apache.org/viewvc?rev=951016&view=rev
Log:
Fix 1.6ism

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/crypt/Decryptor.java

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=951016&r1=951015&r2=951016&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 14:58:02 2010
@@ -26,6 +26,7 @@ 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;
@@ -47,9 +48,16 @@ public class Decryptor {
 
     private void generatePasswordHash(String password) throws NoSuchAlgorithmException {
         MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
+        
+        byte[] passwordBytes;
+        try {
+           passwordBytes = password.getBytes("UTF-16LE");
+        } catch(UnsupportedEncodingException e) {
+           throw new RuntimeException("Your JVM is broken - UTF16 not found!");
+        }
 
         sha1.update(info.getVerifier().getSalt());
-        byte[] hash = sha1.digest(password.getBytes(Charset.forName("UTF-16LE")));
+        byte[] hash = sha1.digest(passwordBytes);
 
         byte[] iterator = new byte[4];
         for (int i = 0; i<50000; i++) {



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


Mime
View raw message