Android Https 双向认证

1.准备好客户端双向认证的两个证书

在res/raw文件夹下放入.bks的密文和.keystore的文件

2.设置传输Https双向认证的HttpClient

public HttpClient getHc() {
		hc = new DefaultHttpClient();
		try {

			KeyStore kks = KeyStore.getInstance("PKCS12");

			KeyStore tks = KeyStore.getInstance("BKS");
			kks.load(

			this.getResources().openRawResource(

			R.raw.user), "123456".toCharArray());

			tks.load(this.getResources().openRawResource(R.raw.cacert),
					"123456".toCharArray());

			SSLSocketFactory socketFactory = new SSLSocketFactory(kks,
					"123456", tks);

			Scheme sch = new Scheme("https", socketFactory, 443);
			hc.getConnectionManager().getSchemeRegistry().register(sch);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return hc;
	}
3.使用HttpClient进行https协议的传输。

你可能感兴趣的:(android,https,双向认证)