How do I get cryptographic security providers?

package org.kodejava.example.security;

import java.security.Provider;
import java.security.Security;
import java.util.Set;
import java.util.HashSet;

public class SecurityProvider {
    public static void main(String[] args) {
        //
        // Create a set so that we can have a unique result.
        //
        Set result = new HashSet();

        //
        // Returns an array containing all the installed providers.
        //
        Provider[] providers = Security.getProviders();

        for (Provider provider : providers) {

            //
            // Get provider's property keys
            //
            Set keys = provider.keySet();
            for (Object key : keys) {
                String data = (String) key;
                data = data.split(" ")[0];

                //
                // Service type started by the "Alg.Alias" string
                //
                if (data.startsWith("Alg.Alias")) {
                    data = data.substring(10);
                }

                data = data.substring(0, data.indexOf('.'));
                result.add(data);
            }
        }

        for (Object o : result) {
            System.out.println("Service Type = " + o);
        }
    }
}

The example result of our code:

Service Type = KeyFactory
Service Type = TransformService
Service Type = CertPathBuilder
Service Type = Cipher
Service Type = SecureRandom
Service Type = Signature
Service Type = AlgorithmParameterGenerator
Service Type = KeyPairGenerator
Service Type = XMLSignatureFactory
Service Type = CertificateFactory
Service Type = MessageDigest
Service Type = KeyInfoFactory
Service Type = KeyAgreement
Service Type = CertStore
Service Type = Configuration
Service Type = SSLContext
Service Type = SaslServerFactory
Service Type = AlgorithmParameters
Service Type = TrustManagerFactory
Service Type = GssApiMechanism
Service Type = TerminalFactory
Service Type = Mac
Service Type = KeyGenerator
Service Type = Policy
Service Type = CertPathValidator
Service Type = SaslClientFactory
Service Type = SecretKeyFactory
Service Type = KeyManagerFactory
Service Type = KeyStore
Service Type = Provider

Wayan Saryada

Programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, Hibernate / JPA.

Leave a Reply