0

我有一个要传递的字符串,它表示由以下内容生成的 X509Certificate:

String strMessage = 
      Base64.encodeToString(chain[0].getEncoded(), android.util.Base64.NO_WRAP);

这样用户就可以查看证书并可能接受它。如果他们决定接受它,我需要创建一个 Keystore 对象,将其添加到我的自定义 SSL 工厂(如这里:)

private SSLSocketFactory newSslSocketFactory(boolean trustCert, String cert) {
    try {
        KeyStore trusted = KeyStore.getInstance("BKS");
        if(trustCert) {
            String cert_begin = "-----BEGIN CERTIFICATE-----\n";
            String end_cert = "-----END CERTIFICATE-----";
            String strCert = cert_begin + cert + end_cert;

            byte[] bytes = Base64.decode(cert.getBytes(), Base64.DEFAULT);                    
            InputStream bis = new ByteArrayInputStream(bytes);
            try {
                trusted.load(bis, "password".toCharArray());
            }
            catch(Exception e) {
                int j;
                j = 10;
            }
            finally {
                bis.close();
            }
        }
        AdditionalKeyStoresSSLSocketFactory af = new AdditionalKeyStoresSSLSocketFactory(trusted, null, mTrustCert, mCert);
        af.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
        return af;
    } 
    catch (Exception e)  {
        throw new AssertionError(e);
    }
}

但这似乎不起作用。当我遍历我的列表时,它没有找到它有什么想法吗?/洛伦

4

0 回答 0