Java 自签名证书
我使用带有自签名证书的主机。因此,我从我的域下载了证书,并使用创建了.bks文件 我需要建立https连接并从我的Web服务检索数据。我使用ksoap2库。我复制并使用了ksoap2 wiki中声明的类 这是我创建密钥库的方法Java 自签名证书,java,android,ssl-certificate,ksoap2,Java,Android,Ssl Certificate,Ksoap2,我使用带有自签名证书的主机。因此,我从我的域下载了证书,并使用创建了.bks文件 我需要建立https连接并从我的Web服务检索数据。我使用ksoap2库。我复制并使用了ksoap2 wiki中声明的类 这是我创建密钥库的方法 MainActivity.java // Get an instance of the Bouncy Castle KeyStore format try { this.keyStore = KeyStore.getInstance
MainActivity.java
// Get an instance of the Bouncy Castle KeyStore format
try {
this.keyStore = KeyStore.getInstance("BKS");
} catch (KeyStoreException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Get the raw resource, which contains the keystore with
// your trusted certificates (root and any intermediate certs)
InputStream in = this.getApplicationContext().getResources().openRawResource(R.raw.myCer);
try {
// Initialize the keystore with the provided trusted certificates
// Also provide the password of the keystore
this.keyStore.load(in, "myPass".toCharArray());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
this.sslSocketFactory = new ConnectionWithSelfSignedCertificate(this.keyStore).getSSLSocketFactory();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这是来自AsyncTask的代码
background task
final HttpsTransportSE transportSE = new HttpsTransportSE(URL, PORT, SERVICE, TIMEOUT);
try {
((HttpsServiceConnectionSE) transportSE.getServiceConnection()).setSSLSocketFactory(this.sslSocketFactory);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
如果我调用transportSE.call(SOAP\u操作,信封);我得到IOException,主机名“www.marpel.cz”未经验证。我做错了什么
我有一个ICS 4.1.2设备。首先,您是否使用自签名证书 如果是,请点击此链接:
您需要额外的类来创建https连接和接受证书。当一切准备就绪后,您可以调用您的
transportSE
我的第一篇文章中的代码工作正常。我发现自签名证书是为不同的域颁发的。我修好了证书,一切正常
固定证书在这里运行
谢谢你,马丁