我明白這是不是很困難,但非常不幸,我卡在這裏,並從昨天開始打架,我遵循這個Mutual Authentication in Android教程,放置一個密鑰庫在資源和嘗試連接到我的服務器通過SSL,但得到以下異常安卓到服務器通信使用SSL與Bouncy城堡
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
。
任何幫助表示讚賞。
我有同樣的問題。我的代碼在CertificateFactory cf = CertificateFactory.getInstance(「X.509」,「BC」)行中給出錯誤。我如何使用這個類來避免錯誤?謝謝 – Hilal
@Hilal分享你的錯誤跟蹤,大致我可以建議你檢查你的提供者列表,可能是BC提供者不在列表中 – SSH
我不能粘貼整個錯誤,因爲stackoverflow不允許:)另外我怎樣才能檢查提供者列表?這裏是錯誤; com.android.org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateFactory $ ExCertificateException 09-20 12:48:02.042 20236-20350/com.example.hilalinan.cert W/System.err:at com。 android.org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateFactory.engineGenerateCertificate(CertificateFactory.java:220) 09-20 12:48:02.042 20236-20350/com.example.hilalinan.cert W/System.err: – Hilal