0

I have:

String text = // same String (text)
byte[] byteArray = org.apache.commons.codec.binary.Base64.decodeBase64(text);
System.out.println("Length: " + byteArray.length);

And the results in Windows is 31 and on Linux it's 32. I tried with sun.misc.BASE64Decoder and pretty much had the same issue...

How come the results are different lengths on the different operating systems, and how do I make it fix it so that it works on both?

5
  • Where does text come from? Are you sure it's the same in both cases? Commented Apr 23, 2012 at 18:52
  • @axtavt I think you might be onto something. When I do text.length on linux and Windows, there's a difference. The linux version is longer. It's taken from the command line. Commented Apr 23, 2012 at 19:00
  • @axtavt That's also with using trim()... Commented Apr 23, 2012 at 19:04
  • Just solved it. Eureka!! The command line argument in linux has to be between single quotes otherwise the args[x] are not equal in windows and linux. Wth is that about? Commented Apr 23, 2012 at 19:10
  • @Stephane: we could tell you if you showed us what text was. Commented Apr 23, 2012 at 19:49

3 Answers 3

3

Probably because the character encoding used by default on Windows is different that the one on Linux.

Can you try with a simple byte arrary , instead of String as the input.

Sign up to request clarification or add additional context in comments.

2 Comments

Unlikely there is something to do with encodings. Base64 is ASCII based.
I just tried byte[] ciphertextArray = Base64.decodeBase64(text.getBytes()); and I still got the same results.
1

I guess it could be caused by the line separator which defaults to ("\r\n") and ("\n") respectively. Why don't you try without those (well, if that's the problem).

Just my two cents.

1 Comment

The string doesn't contain these characters
1

In this specific case the issue was the String text was different. When loading from the command line, in Linux you have to add single quotes before and after the text in the command line otherwise it appends something to the String which Windows doesn't.

Comments

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.