Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-decodeBase64应用程序崩溃_Java_Android_Encryption - Fatal编程技术网

Java Android-decodeBase64应用程序崩溃

Java Android-decodeBase64应用程序崩溃,java,android,encryption,Java,Android,Encryption,我必须加密一个字符串,但应用程序没有达到加密方法,它在加载时崩溃 我正在使用ApacheCommons编解码器库 private EditText txtPass = (EditText)findViewById(R.id.txtPass); public String key = txtPass.getText().toString(); public byte[] key_Array = org.apache.commons.codec.binary.Base64.decodeBase64(

我必须加密一个字符串,但应用程序没有达到加密方法,它在加载时崩溃
我正在使用ApacheCommons编解码器库

private EditText txtPass = (EditText)findViewById(R.id.txtPass);
public String key = txtPass.getText().toString();
public byte[] key_Array = org.apache.commons.codec.binary.Base64.decodeBase64(key);
由于某种原因,该应用程序在第三行崩溃

我的日志

12-03 14:03:31.441  23420-23420/com.example.cristiano.automacao V/ActivityThread﹕ Class path: /data/app/com.example.cristiano.automacao-2.apk, JNI path: /data/data/com.example.cristiano.automacao/lib
12-03 14:03:31.591  23420-23420/com.example.cristiano.automacao W/dalvikvm﹕ VFY: unable to resolve static method 8974: Lorg/apache/commons/codec/binary/Base64;.decodeBase64 (Ljava/lang/String;)[B
12-03 14:03:31.601  23420-23420/com.example.cristiano.automacao W/dalvikvm﹕ VFY: unable to resolve static method 8984: Lorg/apache/commons/codec/binary/Base64;.encodeBase64String ([B)Ljava/lang/String;
12-03 14:03:31.611  23420-23420/com.example.cristiano.automacao W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41c7b438)
有什么线索吗

已更新

我将代码更改为:

public static String key = "1234";
public static byte[] key_Array = decodeBase64(key);
但现在我犯了另一个错误

java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64
试试这个:

// decode data from base 64
    private static byte[] decodeBase64(String dataToDecode)
        {
            byte[] dataDecoded = Base64.decode(dataToDecode, Base64.DEFAULT);
            return dataDecoded;
        }

//enconde data in base 64
        private static byte[] encodeBase64(byte[] dataToEncode)
        {
            byte[] dataEncoded = Base64.encode(dataToEncode, Base64.DEFAULT);
            return dataEncoded;
        }

使用org.apache.commons.codec.binary.Base64库时,只需创建一个Base64对象,并使用它在Android中进行编码或解码

编码 Base64 ed=新的Base64()

字符串编码=新字符串(ed.encode(“Hello.getBytes())

将“Hello”替换为要以字符串格式编码的文本

破译 Base64 ed=新的Base64()

已解码字符串=新字符串(ed.decode(encoded.getBytes())


此处encoded是要解码的字符串变量

您正在输入一个字符串
您应该为decode方法指定key.getBytes()

为什么要使用全名“org.apache.commons.codec.binary.Base64.decodeBase64”?您必须导入库,只需使用“decodeBase64(key);”。我更改了它。但问题依然存在。我认为问题在于静态方法。检查logcat:“无法解析静态方法8974”