How do I get cryptographic security providers?

package org.kodejava.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 results.
        Set<String> results = new HashSet<>();

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

        for (Provider provider : providers) {

            // Get provider's property keys
            Set<Object> 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('.'));
                results.add(data);
            }
        }

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

The example result of our code:

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.