我知道这不是那么困难,但非常不幸的是,我从昨天开始就被困在这里并与之抗争,我已经按照这个Android 教程中的相互身份验证,在资源中放置一个密钥库并尝试通过 SSL 连接到我的服务器,但是得到以下异常
java.lang.RuntimeException:org.spongycastle.jcajce.provider.asymmetric.x509.CertificateFactory$ExCertificateException
我已将我的sslapptruststore.pfx
文件放在res/raw/sslapptruststore.pfx
并使用这段代码
try {
KeyStore clientCert = KeyStore.getInstance("PKCS12");
clientCert.load(getResources().openRawResource(R.raw.sslapptruststore), "123456".toCharArray());// this line causes exception
HttpClient httpClient = null;
HttpParams httpParams = new BasicHttpParams();
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(clientCert, null, null);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https", sslSocketFactory, 8443));
httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, registry), httpParams);
HttpPost httpPost = new HttpPost(
"https://192.168.1.113:8443/CertProvider");
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("csr", csr.toString()));
// Url Encoding the POST parameters
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
// Making HTTP Request
// HttpResponse response = null;
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = "";
response = httpClient.execute(httpPost, responseHandler);
} catch (Exception e) {
Log.e("", e.getMessage());
}
我也搜索过,但其他人正在使用.bks
.
任何帮助表示赞赏。