2 limjiregister limjiregister 于 2016.03.02 12:28 提问

安卓的base64在安卓解码不了,怎么回事

在那些解码网站上:http://www1.tc711.com/tool/BASE64.htm是解码出来的,但是在安卓解不出来,不知道为什么??

求熟悉的帮破一下,这个东西搞了一个多少时....搞不懂,都同样的代码,怎么就不行呢?

提示错误:是不是在java有什么特殊情况解码呢?这乱码在网站都是可以解出来

java.lang.IllegalArgumentException: bad base-64

 package china.testfour;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    String context = "WzAwOjAxLjQ2XeS9nOivjTrpu4TlrrbpqbkNClswMDowMi41MV3kvZzmm7I66buE5a626am5DQpbMDA6MzYuODVd5LuN5piv6Zuo5aScDQpbMDA6MzguODZd5Yed5pyb56qX5aSW5rKJ6buY55qE5aSp6ZmFDQpbMDA6NDMuMjZd6Zeu6IuN5aSp5Y+v5Lya55+l5b+D6YeM55qE5oSf6KeJDQpbMDA6NTIuOTZd6ZqP552A5bKB5pyIDQpbMDA6NTQuNjdd5peg5bC954ix5b+16JeP5Zyo5LqO5b+D6YeMDQpbMDA6NTkuMDNd6LGh5Yaw5bCB55qE55y85YWJ5aSx5Y675LqG5pa55ZCRDQpbMDE6MDguNDRd6K6p6Zuo54K56L276L2755qE5rSS6L+HDQpbMDE6MTEuOTdd5by65oqK5b+n6YOB5YaN5o6p55uWDQpbMDE6MTUuMzFd5YOP56KO5pif6Zeq6Zeq5LqO5aSp56m65Y+r5ZSk5L2gDQpbMDE6MjYuNzBd6YGl5pyb55u85pybDQpbMDE6MjguMjBd6IO95YOP5riF6aOO6Zmq5Ly05aW56aOY5Y67DQpbMDE6MzIuNjNd6K6p5a2k5Y2V55qE6IeC5byv5LiA5YaN5oqx57Sn5L2gDQpbMDE6NDIuNDNd5Zue5pyb5b6A5pel5aaC6Zu+5Ly85qKmDQpbMDE6NDUuODhd5peg5aWI55qE6L275Y+55piv5aW555qE5qyi56yR5aOwDQpbMDE6N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d5pyf5b6F5oiR6L+Z5LiA55Sf5YaN5Lya5L2gDQpbMDQ6MjguMjFd5LuN5piv6Zuo5aScDQpbMDQ6MjkuOTZd5Yed5pyb56qX5aSW5rKJ6buY55qE5aSp6ZmFDQpbMDQ6MzQuMzNd6Zeu6IuN5aSp5Y+v5Lya55+l5b+D6YeM55qE5oSf6KeJDQpbMDQ6NDcuODJd6ZqP552A5bKB5pyIDQpbMDQ6NDkuMzdd5peg5bC954ix5b+16JeP5Zyo5LqO5b+D6YeMDQpbMDQ6NTMuNjNd6LGh5Yaw5bCB55qE55y85YWJ5aSx5Y675LqG5pa55ZCRDQo=";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String result = new String(Base64.decode(context,Base64.DEFAULT));



        Log.d("ddd", result);
    }
}

1个回答

rui888
rui888   Ds   Rxr 2016.03.02 13:03
已采纳
import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException;
import com.sun.org.apache.xml.internal.security.utils.Base64;

 public static void main(String[] args) {
        String context = "WzAwOjAxLjQ2XeS9nOivjTrpu4TlrrbpqbkNClswMDowMi41MV3kvZzmm7I66buE5a626am5DQpbMDA6MzYuODVd5LuN5piv6Zuo5aScDQpbMDA6MzguODZd5Yed5pyb56qX5aSW5rKJ6buY55qE5aSp6ZmFDQpbMDA6NDMuMjZd6Zeu6IuN5aSp5Y+v5Lya55+l5b+D6YeM55qE5oSf6KeJDQpbMDA6NTIuOTZd6ZqP552A5bKB5pyIDQpbMDA6NTQuNjdd5peg5bC954ix5b+16JeP5Zyo5LqO5b+D6YeMDQpbMDA6NTkuMDNd6LGh5Yaw5bCB55qE55y85YWJ5aSx5Y675LqG5pa55ZCRDQpbMDE6MDguNDRd6K6p6Zuo54K56L276L2755qE5rSS6L+HDQpbMDE6MTEuOTdd5by65oqK5b+n6YOB5YaN5o6p55uWDQpbMDE6MTUuMzFd5YOP56KO5pif6Zeq6Zeq5LqO5aSp56m65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DM6NTYuMThd5q+P5aSp5aSa5LmI5aSa5LmI55qE6ZyA6KaBDQpbMDM6NTkuOTNd5rC46L+c5LiO5L2g5oqx5oul552ADQpbMDQ6MDMuNDZd5b+Y5o6J5LiW6Ze05LiA5YiH55eb6Ium5oKy5ZOADQpbMDQ6MTAuMjFd57q15L2/5YiG5byA5YiG5byA5aSa5LmI6L+cDQpbMDQ6MTQuMDZd5Lmf5Lya5ZCs5Yiw5L2g5ZG85ZSkDQpbMDQ6MTcuNjJd5pyf5b6F5oiR6L+Z5LiA55Sf5YaN5Lya5L2gDQpbMDQ6MjguMjFd5LuN5piv6Zuo5aScDQpbMDQ6MjkuOTZd5Yed5pyb56qX5aSW5rKJ6buY55qE5aSp6ZmFDQpbMDQ6MzQuMzNd6Zeu6IuN5aSp5Y+v5Lya55+l5b+D6YeM55qE5oSf6KeJDQpbMDQ6NDcuODJd6ZqP552A5bKB5pyIDQpbMDQ6NDkuMzdd5peg5bC954ix5b+16JeP5Zyo5LqO5b+D6YeMDQpbMDQ6NTMuNjNd6LGh5Yaw5bCB55qE55y85YWJ5aSx5Y675LqG5pa55ZCRDQo=";
         String result;
        try {
            result = new String(Base64.decode(context));
             System.out.println(result);
        } catch (Base64DecodingException e) {
            e.printStackTrace();
        }
    }

没问题吖。

图片说明

limjiregister
limjiregister 回复无法显示此用户: 哎,能来代码能用,就是log打不出来,奇怪了,显示在textview上竟然可以显示.....
接近 2 年之前 回复
rui888
rui888 回复limjiregister: 我直接main方法测试的。你再试试。
接近 2 年之前 回复
limjiregister
limjiregister 啊,我在Android studio没log出来,哎,不知道怎么回事,看来不是代码的问题了?
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!