get Supported Ciphers - Java Network

Java examples for Network:SSL

Description

get Supported Ciphers

Demo Code

// Licensed to the Apache Software Foundation (ASF) under one
import org.apache.log4j.Logger;
import javax.net.ssl.SSLContext;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main{
    public static String[] getSupportedCiphers()
            throws NoSuchAlgorithmException {
        String[] availableCiphers = getSSLContext().getSocketFactory()
                .getSupportedCipherSuites();
        Arrays.sort(availableCiphers);
        return availableCiphers;
    }/*w ww  . ja v a 2s  . c o m*/
    public static SSLContext getSSLContext()
            throws NoSuchAlgorithmException {
        return SSLContext.getInstance("TLSv1");
    }
    public static SSLContext getSSLContext(String provider)
            throws NoSuchAlgorithmException, NoSuchProviderException {
        return SSLContext.getInstance("TLSv1", provider);
    }
}

Related Tutorials