/*
 * [ShowKeyStoreProviders.java]
 *
 * Summary: List all supported formats of the Keystore File,.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2008-04-20 based on code from http://exampledepot.com/egs/java.security/ListServices.html
 */
package com.mindprod.example;

import java.security.Provider;
import java.security.Security;

import static java.lang.System.*;

/**
 * List all supported formats of the Keystore File,.
 * <p/>
 * i.e. Supported KeyStore providers.
 * e.g.
 * JKS
 * CaseExactJKS
 * JKS
 * PKCS12
 * JCEKS
 * Windows-ROOT
 * Windows-MY
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2008-04-20 ased on code from http://exampledepot.com/egs/java.security/ListServices.html
 * @since 2008-04-20
 */
public class ShowKeyStoreProviders
    {
    /**
     * Get list of Keystore providers supported.
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        final String serviceTypeOfInterest = "KeyStore";
        // get list of all providers
        final Provider[] providers = Security.getProviders();
        for ( Provider provider : providers )
            {
            // Get services provided by each provider
            // unfortunately legacy keySet() returns Set<Object> instead of Set<String>
            for ( Object okey : provider.keySet() )
                {
                final String key = ( ( String ) okey ).split( " " )[ 0 ];
                if ( key.startsWith( serviceTypeOfInterest + "." ) )
                    {
                    // strip off lead KeyStore.
                    out.println( key.substring( serviceTypeOfInterest.length() + 1 ) );
                    }
                }
            }
        }
    }