Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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
Android 将SSL证书bye[]数组从jni带到Flatter_Android_Kotlin_Java Native Interface_Flutter Http - Fatal编程技术网

Android 将SSL证书bye[]数组从jni带到Flatter

Android 将SSL证书bye[]数组从jni带到Flatter,android,kotlin,java-native-interface,flutter-http,Android,Kotlin,Java Native Interface,Flutter Http,我通过将证书安全地存储在JNI中并在运行时获取它来执行flutter中的证书固定。但是当我从JNI获取数据时,我得到了坏的数据(pkcs8\u x509.c:626),errno=0)。如果我直接在颤振代码中设置它,钉住就可以工作 List\u crt=[45,45,45,45,45,66,69,71,73,78,…] 以下是JNI方法: extern "C" JNIEXPORT jintArray JNICALL Java_com_package_android_MainA

我通过将证书安全地存储在JNI中并在运行时获取它来执行flutter中的证书固定。但是当我从JNI获取数据时,我得到了坏的数据(pkcs8\u x509.c:626),errno=0)。如果我直接在颤振代码中设置它,钉住就可以工作
List\u crt=[45,45,45,45,45,66,69,71,73,78,…]

以下是JNI方法:

extern "C" JNIEXPORT jintArray JNICALL Java_com_package_android_MainActivity_getCert
        (JNIEnv *env, jobject This)
{
    int a[] ={45,45,45,45,45,...};
    jintArray ret = env->NewIntArray(sizeof(a));
    env->SetIntArrayRegion(ret, 0, 6, a);
    return ret;
}
MainActivity.kt:

external fun getCert(): IntArray
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
            call, result ->
            if (call.method == "cert") {
                result.success(getCert())
            }
        }
    }
颤振代码:

      List<int> _crt;
      _crt = await _platform.invokeMethod("cert");
      //print("CRT: " + _crt.length);
      SecurityContext context = SecurityContext(withTrustedRoots: true);
      context.setTrustedCertificatesBytes(_crt);
      httpClient = new HttpClient(context: context);
List\u crt;
_crt=wait_platform.invokeMethod(“cert”);
//打印(“阴极射线管:”+阴极射线管长度);
SecurityContext上下文=SecurityContext(withTrustedRoots:true);
setTrustedCertificatesBytes(_crt);
httpClient=新的httpClient(上下文:上下文);
我不明白为什么从JNI返回的int数组不起作用,但如果我直接在flatter中设置它就没有问题了?

sizeof(a)
没有给出
a
中的元素数。它提供所有元素的总大小,以字节为单位

您需要的是
sizeof(a)/sizeof(int)
sizeof(a)/sizeof(a[0])