How to use SSL socket in Java

I have been searching for a long time how to use SSL socket in java…. we will continue soon.

Code:

 SSLContext ctx = null;
// load keystore
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
char[] password = getPassword();
InputStream in = ClassLoader.getSystemResourceAsStream(keystore);
ks.load(in, password);
in.close();
// set-up SSLContext
KeyManagerFactory kmf = KeyManagerFactory.getInstance(“SunX509”, “SunJSSE”);
kmf.init(ks, password);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(“PKIX”, “SunJSSE”);
tmf.init(ks);
ctx = SSLContext.getInstance(“TLS”);
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

Advertisements