diff options
author | Nick Burch <nick@apache.org> | 2010-06-03 14:58:02 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2010-06-03 14:58:02 +0000 |
commit | 9c68267a68255e32aae5f4276af6b39f0def1162 (patch) | |
tree | 07b50643b68bd9094511000a30c6f48a07f30709 | |
parent | 390c6f797ad5d4cd5cfbf90331e5d0bb8608f39f (diff) | |
download | poi-9c68267a68255e32aae5f4276af6b39f0def1162.tar.gz poi-9c68267a68255e32aae5f4276af6b39f0def1162.zip |
Fix 1.6ism
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@951016 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/poi/poifs/crypt/Decryptor.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/java/org/apache/poi/poifs/crypt/Decryptor.java b/src/java/org/apache/poi/poifs/crypt/Decryptor.java index a47100d696..7b36dc4e01 100644 --- a/src/java/org/apache/poi/poifs/crypt/Decryptor.java +++ b/src/java/org/apache/poi/poifs/crypt/Decryptor.java @@ -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++) { |