浏览 2152 次
锁定老帖子 主题:处理 https 工具
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-01-21
最后修改:2010-01-26
import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import org.apache.log4j.Logger; /** * @author Squall * */ public class TrustUtil { private static final Logger logger = Logger.getLogger(TrustUtil.class); /** * 获取验证信息 通过验证 */ public static void getTrust(){ logger.info("getTrust function"); X509TrustManager xtm = new X509TrustManager(){ // X509Certificate[] chain; // // public X509Certificate[] getAcceptedIssuers() { // throw new UnsupportedOperationException(); // } // // public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { // throw new UnsupportedOperationException(); // } // // public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { // this.chain = chain; // this.checkServerTrusted(chain, authType); // } public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { System.out.println("检查客户端的可信任状态..."); } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { System.out.println("检查服务器的可信任状态"); } public X509Certificate[] getAcceptedIssuers() { System.out.println("获取接受的发行商数组..."); return null; } }; TrustManager mytm[] = {xtm}; SSLContext sc = null; try { sc = SSLContext.getInstance("SSL"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } try { sc.init(null,mytm,null); } catch (KeyManagementException e) { e.printStackTrace(); } HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2010-12-20
怎么调用?
请举一个 列子 好么?? |
|
返回顶楼 | |