wokier / gwt-crypto

Automatically exported from code.google.com/p/gwt-crypto
8 stars 1 forks source link

ArrayIndexOutOfBoundsException: line 102 of com.googlecode.gwt.crypto.util.Sys #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use Eclipse 3.5 and GWT 1.7 plugin
2. Setup a Google web application Run Configuration
3. Run as web application. Application run in GWT Hostedmode.

What is the expected output? What do you see instead?
Expectaion is that SHA1Digest encrypts a text value. There are 9-
characters in the text value to encrypt. What I see 
is "java.lang.ArrayIndexOutOfBoundsException: 9" at 
SHA1Digest.unpackWord method.
In Web Mode, this problem does not exist.

What version of the product are you using? On what operating system?
Windows XP SP3. IE8.

Please provide any additional information below.

Original issue reported on code.google.com by lloyd.bo...@gmail.com on 16 Sep 2009 at 12:53

GoogleCodeExporter commented 9 years ago
Exception stack trace logged in GWT Hostedmode follows:

java.lang.ArrayIndexOutOfBoundsException: 9
    at com.googlecode.gwt.crypto.bouncycastle.digests.SHA1Digest.unpackWord
(SHA1Digest.java:77)
    at com.googlecode.gwt.crypto.bouncycastle.digests.SHA1Digest.doFinal
(SHA1Digest.java:102)

Original comment by lloyd.bo...@gmail.com on 16 Sep 2009 at 1:01

GoogleCodeExporter commented 9 years ago
Sample code that has the above exception follows:

SHA1Digest digest = new SHA1Digest();
byte[] inputBytes = Str.toBytes(passwordString.toCharArray());
digest.update(inputBytes, 0, inputBytes.length);
digest.doFinal(inputBytes, 0);

Original comment by lloyd.bo...@gmail.com on 16 Sep 2009 at 1:06

GoogleCodeExporter commented 9 years ago

Original comment by moor...@gmail.com on 4 Oct 2009 at 4:08

GoogleCodeExporter commented 9 years ago
Here's a PDF of the code that the SHA1Digest class is based upon:
http://www.cacr.math.uwaterloo.ca/hac/about/chap9.pdf

Original comment by moor...@gmail.com on 4 Oct 2009 at 4:14

GoogleCodeExporter commented 9 years ago
Lloyd,

After looking at this, I believe you need to zero pad the inputBytes as so:

 String passwordString = "abcdefghi";
 SHA1Digest digest = new SHA1Digest();
 byte[] inputBytes = new byte[digest.getDigestSize()];
 byte[] pwBytes = passwordString.getBytes();
 for (int i = 0; i < pwBytes.length; i++) {
         inputBytes[i] = pwBytes[i];
 }

 digest.update(inputBytes, 0, inputBytes.length);

 int val = digest.doFinal(inputBytes, 0);

Please try this and let me know if it works for you.

Original comment by moor...@gmail.com on 4 Oct 2009 at 4:43

GoogleCodeExporter commented 9 years ago
This is not a bug.

Original comment by moor...@gmail.com on 8 Oct 2009 at 4:37

GoogleCodeExporter commented 9 years ago
after this i'm getting this                                                     
 00:08:17,234 [ERROR] Line 45: The method getBytes() is undefined for the type 
String   for   byte[] pwBytes = passwordString.getBytes();

Original comment by javaSp...@gmail.com on 29 Sep 2010 at 9:28

GoogleCodeExporter commented 9 years ago
javaSparx,

I don't follow you.  What is the situation where you're getting that error?

Please post code if possible.

Original comment by moor...@gmail.com on 29 Sep 2010 at 3:04