system Trust Manager - Java Security

Java examples for Security:Trust Manager

Description

system Trust Manager

Demo Code


//package com.java2s;

import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;

import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(systemTrustManager());
    }//from w w w .  j  a  va  2 s  . co m

    public static X509TrustManager systemTrustManager()
            throws NoSuchAlgorithmException, KeyStoreException {
        return trustManagerForKeyStore(null);
    }

    public static X509TrustManager trustManagerForKeyStore(KeyStore ks)
            throws NoSuchAlgorithmException, KeyStoreException {
        TrustManagerFactory tmf = TrustManagerFactory
                .getInstance(TrustManagerFactory.getDefaultAlgorithm());

        tmf.init(ks);

        return (X509TrustManager) tmf.getTrustManagers()[0];
    }
}

Related Tutorials