crypto
List available cryptographic services
In this example we shall show you how to list all the available cryptographic services. To list all the available cryptographic services one should perform the following steps:
getProviders()
API method of Security to get an array of the Providers.keySet()
API method of Provider.as described in the code snippet below.
package com.javacodegeeks.snippets.core; import java.security.Provider; import java.security.Security; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; public class ListAvailableCryptographicServices { public static void main(String[] args) { Set<String> serviceTypes = new TreeSet<String>(); // get an array containing all the installed providers Provider[] providers = Security.getProviders(); for (int i=0; i<providers.length; i++) { // get a view of the property keys contained in this provider Set<Object> keys = providers[i].keySet(); for (Iterator<Object> it=keys.iterator(); it.hasNext();) { String key = it.next().toString(); key = key.split(" ")[0]; if (key.startsWith("Alg.Alias.")) { // strip the alias key = key.substring(10); } int index = key.indexOf('.'); serviceTypes.add(key.substring(0, index)); } } for (Iterator<String> it=serviceTypes.iterator(); it.hasNext();) { System.out.println(it.next()); } } }
Output:
AlgorithmParameterGenerator
AlgorithmParameters
CertPathBuilder
CertPathValidator
CertStore
CertificateFactory
Cipher
Configuration
GssApiMechanism
KeyAgreement
KeyFactory
KeyGenerator
KeyInfoFactory
KeyManagerFactory
KeyPairGenerator
KeyStore
Mac
MessageDigest
Policy
Provider
SSLContext
SaslClientFactory
SaslServerFactory
SecretKeyFactory
SecureRandom
Signature
TerminalFactory
TransformService
TrustManagerFactory
XMLSignatureFactory
This was an example of how to list all the available cryptographic services in Java.