Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Read out all Security Provider
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest("hallo".getBytes(Charset.forName("UTF-8")));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
System.out.println("= " + provider.getName() + " =");
System.out.println("\n\n== MESSAGE DIGEST ==");
showHashAlgorithms(provider, MessageDigest.class);
System.out.println("\n\n== CIPHER ==");
showHashAlgorithms(provider, Cipher.class);
System.out.println("\n\n== MAC ==");
showHashAlgorithms(provider, Mac.class);
System.out.println("\n\n== KEY AGREEMENT ==");
showHashAlgorithms(provider, KeyAgreement.class);
System.out.println("\n\n== SIGNATURE ==");
showHashAlgorithms(provider, Signature.class);
System.out.println("\n\n== SECRET KEY FACTORY ==");
showHashAlgorithms(provider, SecretKeyFactory.class);
System.out.println("\n\n== KEY PAIR GEN ==");
showHashAlgorithms(provider, KeyPairGenerator.class);
}
}
private static final void showHashAlgorithms(Provider prov, Class<?> typeClass) {
String type = typeClass.getSimpleName();
List<Provider.Service> algos = new ArrayList<>();
Set<Provider.Service> services = prov.getServices();
for (Provider.Service service : services) {
if (service.getType().equalsIgnoreCase(type)) {
algos.add(service);
}
}
if (!algos.isEmpty()) {
System.out.printf(" --- Provider %s, version %.2f --- %n", prov.getName(), prov.getVersion());
for (Provider.Service service : algos) {
String algo = service.getAlgorithm();
System.out.printf("Algorithm name: \"%s\"%n", algo);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.