1

I sit with a weird problem. I use Apache's commons-codec (ver 1.4). The following code snippet work correctly on my PC (java version 1.6, Glassfish ver 2.1) in a standalone app and in an EJB, but on my server in an EJB it doesn't work correctly (but in a standalone app it works correctly)

...
org.apache.commons.codec.binary.Base64 b64 = new org.apache.commons.codec.binary.Base64();
byte[] bytes = b64.decode(makeSignedBytes(strB64.getBytes("UTF-8")));
...
private byte[] makeSignedBytes(byte[] ubytes)
{
    byte[] sbytes = new byte[ubytes.length];
    for (int i = 0; i < ubytes.length; i++)
    {
        sbytes[i] = (byte)(0x000000FF & ((int) ubytes[i]));
    }
    return sbytes;
}

The input string is:

4-sDHXi_2Tu2a8k8NPs1FBT3t7UvN7CksUV6gfSE_Ks0aiCPbdeGM8qLdC58b2_hFH7lEp8m9cyPYQOTo4E0t66ZYP8n8tRhT87c8iD34pCd80qvP9vIXsNsodRaGzK5

The output byte array should look like this (I've hex printed it):

|E3|EB|03|1D|78|BF|D9|3B|B6|6B|C9|3C|34|FB|35|14|14|F7|B7|B5|2F|37|B0|A4|B1|45|7A|81|F4|84|FC|AB|34|6A|20|8F|6D|D7|86|33|CA|8B|74|2E|7C|6F|6F|E1|14|7E|E5|12|9F|26|F5|CC|8F|61|03|93|A3|81|34|B7|AE|99|60|FF|27|F2|D4|61|4F|CE|DC|F2|20|F7|E2|90|9D|F3|4A|AF|3F|DB|C8|5E|C3|6C|A1|D4|5A|1B|32|B9|

96 bytes long, when the server get's it wrong it's only 93 bytes and looks like this:

|E2|C0|C7|5E|2D|93|BB|66|BC|93|C3|4F|B3|51|41|4F|7B|7B|52|F3|7B|0A|4B|14|57|A8|1F|48|42|AC|D1|A8|82|3D|B7|5E|18|CF|2A|2D|D0|B9|F1|BD|A1|14|7E|E5|12|9F|26|F5|CC|8F|61|03|93|A3|81|34|B7|AE|99|60|FF|27|F2|D4|61|4F|CE|DC|F2|20|F7|E2|90|9D|F3|4A|AF|3F|DB|C8|5E|C3|6C|A1|D4|5A|1B|32|B9|

I have no idea why it works on my pc and not on the server :(

3
  • 1
    Are you sure the Apache's commons-codec's version is strictly the same on your computer and on the server? Maybe the server comes with its own version. Commented Mar 4, 2011 at 10:30
  • I've not looked in the right place :( but I've found it: Commented Mar 4, 2011 at 10:47
  • ./lib/registration/commons-codec-1.3.jar ./domains/domain1/applications/j2ee-apps/anApplication/lib/commons-codec-1.4.jar Commented Mar 4, 2011 at 10:47

1 Answer 1

1

The wrong result is caused by replacing the second character in the input string (U+002D HYPHEN-MINUS) with U+2010 HYPHEN and replacing underscores with spaces. Perhaps it's a result of passing input string through some "smart" text editor. So, actually it looks like you pass a wrong input string in.

Other flaws in your code:

  • makeSignedBytes() method makes no sense and isn't needed
  • strB64.getBytes("UTF-8") is semantically wrong, it should be strB64.getBytes("ASCII")
Sign up to request clarification or add additional context in comments.

1 Comment

The string is the same for both systems (I've check on a byte level).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.