2

I have a big problem : I don't have the same result if I do base64_decode($string); in php or if I do Base64.decode(string); in android.

Example : with this string : WWhiZWWSZpNlaGSTnpljZQ==

In php, result is Yhbee’f“ehd“ž™ce .

In android, the result is Yhbee�f�ehd���ce

I think there is an encoding problem, but I don't know where, the output of my PHP server is ISO-8859-1, I don't find how to tell to Base64.decode to use this type of encoding.

Can you help me please. Thx for answers.

PS : I can't touch the PHP script.

1

3 Answers 3

1

I think this will help you, Don't use .toString() use this instead

var str = "WWhiZWWSZpNlaGSTnpljZQ=="
var decoded = String(Base64.decode(str, Base64.NO_WRAP))

I know this to late to answer :-D

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

Comments

0

You should try this:

 Base64.decode(content.getBytes("ISO-8859-1"), Base64.DEFAULT);

By this You convert the input String content to ISO-8859-1 encoded byte stream that will be decoded from base64.

1 Comment

Guys, it is worth to note that Base64.DEFAULT flag will append '\n' at the end of the result. To avoid this behavior, use Base64.NO_WRAP
0

I think the decode is fine, but Android isn't applying the right encoding (probably utf-8).

Does this content appear on an HTML page? If so, are you properly enforcing the ISO-8859-1 encoding?

Alternatively, you could also switch to UTF-8.

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.