Android PHP Base64 decode with different results

匆匆过客 提交于 2020-01-15 03:34:13

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/15705478/android-php-base64-decode-with-different-results

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!