集册 Java实例教程 创建SSL上下文

创建SSL上下文

欢马劈雪     最近更新时间:2020-01-02 10:19:05

426
创建SSL上下文

/**
来 自 时 代 J a v a 公 众 号 - nowjava.com
**/

import java.net.URL;

import java.security.GeneralSecurityException;

import java.security.SecureRandom;

import javax.net.ssl.HostnameVerifier;

import javax.net.ssl.HttpsURLConnection;

import javax.net.ssl.SSLContext;

import javax.net.ssl.SSLSession;

import javax.net.ssl.X509TrustManager;


public class Main{

    public static void main(String[] argv) throws Exception{

        System.out.println(createSSLContext());

    }

    public static SSLContext createSSLContext()

            throws GeneralSecurityException {

        SSLContext context = SSLContext.getInstance("TLS");/**来自 时代Java**/

        context.init(

                null,

                
展开阅读全文