Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.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 如何在react native中集成自定义证书和trustmanager?_Android_Ios_React Native - Fatal编程技术网

Android 如何在react native中集成自定义证书和trustmanager?

Android 如何在react native中集成自定义证书和trustmanager?,android,ios,react-native,Android,Ios,React Native,这是android java中的代码。它在react native中的等价物是什么?堆栈溢出不允许我发布大部分代码。所以这只是无用的细节。我的问题已经结束了 String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);tmf.init(keystore)

这是android java中的代码。它在react native中的等价物是什么?堆栈溢出不允许我发布大部分代码。所以这只是无用的细节。我的问题已经结束了

        String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);tmf.init(keystore);

        KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");

        kmf.init(keystore, "PASSWORD".toCharArray());

        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[] {};
            }

            public void checkClientTrusted(X509Certificate[] chain,
                                           String authType) throws CertificateException {
            }

            public void checkServerTrusted(X509Certificate[] chain,
                                           String authType) throws CertificateException {
            }
        } };
        final SSLContext sc = SSLContext.getInstance("TLSv1.2");
        sc.init(kmf.getKeyManagers(), trustAllCerts, new java.security.SecureRandom());
        final SSLSocketFactory socketFactory = sc.getSocketFactory();
        HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);
        urlConnection.setSSLSocketFactory(sc.getSocketFactory());

只需尝试为您的开发环境使用受信任的证书。请看