Hello all,
I have a problem with base64 codec and encoding ascii characters. Here`s the
code:
int ok=0, bad=0;
for(int i=128; i<256; i++){
char c = (char)i;
str = "" + c;
String enc = new
String(Base64.encodeBase64(str.getBytes()));
String dec = new
String(Base64.decodeBase64(enc.getBytes()));
if(str.equals(dec)) ok++;
else bad++;
}
System.out.println("ok: " + ok);
System.out.println("bad: " + bad);
I get this:
ok: 80
bad: 48
So, simple encoding and decoding of ascii chars > 128 doesn`t work for me.
Is there some explanation?
I tried this on os x, java5 and java6, doesn`t work, and on java6 on solaris
pc it does. That confuses me totally :)
The other part of the problem is probably linked to this one. I`m trying to
encode a string in my java code, and decode it in some php code that I use.
Is that possible? I guess since base64 is a standard it should work, and yet
it doesn`t on os x, nor on solaris :( Maybe it is linked somehow to the
ascii char problem?
Thanks,
Nikola