Android Bouncy Castle密钥库(BKS):java.io.IOException:密钥库的版本错误
我必须连接到基于REST的Web服务 () 在IE或chrome浏览器中,当我尝试访问此URL时,我会获得一个证书,我必须信任并接受该证书才能继续 之后,我必须输入用户名和密码,然后得到JSON响应 同样的事情,我必须为android应用程序编程Android Bouncy Castle密钥库(BKS):java.io.IOException:密钥库的版本错误,android,web-services,https,certificate,Android,Web Services,Https,Certificate,我必须连接到基于REST的Web服务 () 在IE或chrome浏览器中,当我尝试访问此URL时,我会获得一个证书,我必须信任并接受该证书才能继续 之后,我必须输入用户名和密码,然后得到JSON响应 同样的事情,我必须为android应用程序编程 试过自定义EasySslocketFactory和EasyX509TrustManager,但不起作用。 我得到了以下错误: java.security.cert.CertPathValidator异常:找不到证书路径的信任锚点 使用BKS密钥库, 请
keytool -importcert -v -trustcacerts -file "test.crt" -alias IntermediateCA -keystore "mykeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "bcprov-jdk15on-148.jar" -storetype BKS -storepass abcd1234
keytool -list -keystore "mykeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "bcprov-jdk15on-148.jar" -storetype BKS -storepass abcd1234
public class MyHttpClient extends DefaultHttpClient {
final Context context;
public MyHttpClient(Context context) {
this.context = context;
}
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
// Register for port 443 our SSLSocketFactory with our keystore
// to the ConnectionManager
registry.register(new Scheme("https", newSslSocketFactory(), 443));
return new SingleClientConnManager(getParams(), registry);
}
private SSLSocketFactory newSslSocketFactory() {
try {
// Get an instance of the Bouncy Castle KeyStore format
KeyStore trusted = KeyStore.getInstance("BKS");
// Get the raw resource, which contains the keystore with
// your trusted certificates (root and any intermediate certs)
InputStream in = context.getResources().openRawResource(R.raw.mykeystore);
try {
// Initialize the keystore with the provided trusted certificates
// Also provide the password of the keystore
trusted.load(in, "abcd1234".toCharArray());
} finally {
in.close();
}
// Pass the keystore to the SSLSocketFactory. The factory is responsible
// for the verification of the server certificate.
SSLSocketFactory sf = new SSLSocketFactory(trusted);
// Hostname verification from certificate
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506
sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
return sf;
} catch (Exception e) {
throw new AssertionError(e);
}
}
当我调用webservice时,我得到以下错误:
原因:java.lang.AssertionError:java.io.IOException:密钥存储的版本错误
请告诉我要连接到基于HTTPS的rest webservice需要做什么,该服务具有用户名和密码凭据。
……BC-jar的148版不适用于Android。使用版本146或147 我得到了别人的帮助。 解决方案如下所示:
- 1、 下载工具
- 2、 安装后,打开bks证书,然后查找工具->更改类型
- 3、 选择BKS-V1,然后保存并使用它