Using SSL in java program

import java.net.*;
import java.security.cert.Certificate;
import java.io.*;

import javax.net.ssl.*;

public class SSLTest {

    public static void main(String[] args) throws Exception {
        String https_url = "https://www.google.com/";
        URL url;
        url = new URL(https_url);
        HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
        if (con != null) {
                System.out.println("Response Code : " + con.getResponseCode());
                System.out.println("Cipher Suite : " + con.getCipherSuite());
                System.out.println("\n");
                Certificate[] certs = con.getServerCertificates();
                int i=0;
                for (Certificate cert : certs) {
                    System.out.println("Cert NO : "+i++);
                    System.out.println("Cert Type : " + cert.getType());
                    System.out.println("Cert Hash Code : " + cert.hashCode());
                    System.out.println("Cert Public Key Algorithm : " + cert.getPublicKey().getAlgorithm());
                    System.out.println("Cert Public Key Format : " + cert.getPublicKey().getFormat());
                    System.out.println("\n");
                }
                System.out.println("****** Content of the URL ********");
                BufferedReader br =new BufferedReader(new InputStreamReader(con.getInputStream()));
                String input;
                while ((input = br.readLine()) != null) {
                    System.out.println(input);
                }
                br.close();
        }
    }
}

No comments:

Popular Posts