commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From luc.maison...@free.fr
Subject Re: Base64 encoding problem
Date Wed, 14 Jun 2006 08:10:34 GMT
Selon Priti Menon <pritim@cybage.com>:

Could you try to remove the encoding/decoding part and performing directly:

 String decodedString = new String(s.getBytes());

and to compare the hash codes ?

If this fails, then it would mean the special character is not valid in the
default encoding of your Linux box but valid in the (probably different)
encoding of your Windows box.

The javadoc for the constructor String(byte[]) says:

  The behavior of this constructor when the given bytes are not valid
  in the default charset is unspecified.

In this case, a possible workaround would be to explicitely specify an encoding
for which the special character is valid instead of relying on the default
charset of the system.


Luc

> Hi All,
>
> I am facing a problem with the Base64 encoding class in the commons package.
> i.e. org.apache.commons.codec.binary.Base64
>
> I am trying to encode & decode a string back to its original value. I have
> tried this on windows & linux.
> If you compare the hashcodes of the original string with the new string, it
> returns different values with Linux.
>
> For eg.
> String s = "Matrix ";
> System.out.println("s = " + s.hashCode());
> String s1 = new String(Base64.encodeBase64(s.getBytes()));
> String decodedString = new String(Base64.decodeBase64(s1.getBytes()));
> System.out.println("decodedString = " + decodedString.hashCode());
>
> The output on windows :-
> s = Matrix
> s = -1789003553
> decodedString = -1789003553
>
> The output on linux :-
> s = Matrix?
> s = -1789003553
> decodedString = -1789003650
>
> Has anyone faced this problem before ?
>
> Thanks & Regards,
> Priti
>
> PS. There is a special character in the string after the word 'Matrix'.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message