这是我在主文件中的代码: 你能告诉我如何在android studio中为Android应用程序生成BKS密钥库
OkHttpClient okHttpClient = new OkHttpClient();
try {
KeyStore ksTrust = KeyStore.getInstance("BKS");
InputStream instream = this.getResources().openRawResource(R.raw.keystore);
ksTrust.load(instream, "secret".toCharArray());
// TrustManager decides which certificate authorities to use.
TrustManagerFactory tmf = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ksTrust);
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
okHttpClient.setSslSocketFactory(sslContext.getSocketFactory());
} catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | KeyManagementException e) {
Log.e(TAG,"in catch");
Log.e(TAG,e.toString());
e.printStackTrace();
}
答案 0 :(得分:1)
使用此命令创建bks证书。
keytool -importcert -v -trustcacerts -file“path_to_cert / interm_ca.cer”-alias IntermediateCA -keystore“res / raw / myKeystore.bks”-provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath“path_to_bouncycastle / bcprov -jdk16-145.jar“-storetype BKS -storepass mysecret
详细信息在这里,
http://blog.antoine.li/2010/10/22/android-trusting-ssl-certificates/