Return the available implementations for a service type : Algorithms « Security « Java






Return the available implementations for a service type

  

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

public class Main {
  public static void main(String[] argv) throws Exception {
    Set result = new HashSet();
    String serviceType = "KeyFactory";
    Provider[] providers = Security.getProviders();
    for (int i = 0; i < providers.length; i++) {
      Set keys = providers[i].keySet();
      for (Iterator it = keys.iterator(); it.hasNext();) {
        String key = (String) it.next();
        key = key.split(" ")[0];

        if (key.startsWith(serviceType + ".")) {
          result.add(key.substring(serviceType.length() + 1));
        } else if (key.startsWith("Alg.Alias." + serviceType + ".")) {
          result.add(key.substring(serviceType.length() + 11));
        }
      }
    }
    System.out.println(result);
  }

}
[1.2.840.113549.1.3.1, 
OID.1.2.840.113549.1.1, 
1.2.840.113549.1.1, 
OID.1.2.840.113549.1.3.1, 
1.3.14.3.2.12, 
DSA, DiffieHellman, RSA, DH, 1.2.840.10040.4.1]

   
    
  








Related examples in the same category

1.What is in bouncycastle (bouncy castle)
2.JCE algorithms in BrowserJCE algorithms in Browser
3.Listing All Available Cryptographic Services
4.Get cryptographic security providers
5.Generating a Parameter Set for the Diffie-Hellman Key Agreement Algorithm