2013-03-29 14:39

Android PHP Base64解码具有不同的结果


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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • drlma06060 drlma06060 8年前

    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.

    点赞 评论 复制链接分享
  • donglian3061 donglian3061 8年前

    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.

    点赞 评论 复制链接分享