Java/Security/Providers
List All Provider And Its Algorithms
/*
Buildfile: build.xml
copy-resources:
compile:
[javac] Compiling 1 source file to C:\Java_Dev\WEB\dev\jce\env\build
run:
[java] SUN version 1.5
[java] Alg.Alias.KeyFactory.1.2.840.10040.4.1
[java] Alg.Alias.Signature.1.2.840.10040.4.3
[java] Alg.Alias.KeyPairGenerator.OID.1.2.840.10040.4.1
[java] Signature.SHA1withDSA KeySize
[java] CertStore.LDAP LDAPSchema
[java] Signature.SHA1withDSA ImplementedIn
[java] Provider.id name
[java] CertPathValidator.PKIX ValidationAlgorithm
[java] CertPathBuilder.PKIX
[java] MessageDigest.SHA-384
[java] Alg.Alias.KeyFactory.1.3.14.3.2.12
[java] CertStore.LDAP
[java] Signature.NONEwithDSA SupportedKeyClasses
[java] AlgorithmParameterGenerator.DSA
[java] MessageDigest.SHA-256
[java] MessageDigest.SHA-512
[java] Alg.Alias.KeyPairGenerator.1.3.14.3.2.12
[java] Alg.Alias.Signature.SHA/DSA
[java] Provider.id version
[java] Alg.Alias.Signature.1.3.14.3.2.13
[java] SecureRandom.SHA1PRNG
[java] Alg.Alias.Signature.DSS
[java] CertStore.Collection
[java] KeyStore.JKS ImplementedIn
[java] KeyFactory.DSA ImplementedIn
[java] MessageDigest.SHA ImplementedIn
[java] Signature.SHA1withDSA
[java] AlgorithmParameters.DSA
[java] CertPathBuilder.PKIX ValidationAlgorithm
[java] MessageDigest.SHA
[java] Alg.Alias.AlgorithmParameters.1.3.14.3.2.12
[java] AlgorithmParameterGenerator.DSA ImplementedIn
[java] MessageDigest.MD5 ImplementedIn
[java] Alg.Alias.Signature.DSA
[java] Alg.Alias.CertificateFactory.X509
[java] KeyStore.JKS
[java] CertificateFactory.X.509
[java] Signature.SHA1withDSA SupportedKeyClasses
[java] Alg.Alias.Signature.DSAWithSHA1
[java] MessageDigest.MD5
[java] KeyPairGenerator.DSA
[java] Alg.Alias.Signature.SHAwithDSA
[java] MessageDigest.MD2
[java] Alg.Alias.Signature.OID.1.2.840.10040.4.3
[java] CertStore.ru.sun.security.IndexedCollection ImplementedIn
[java] CertificateFactory.X.509 ImplementedIn
[java] Alg.Alias.Signature.RawDSA
[java] KeyPairGenerator.DSA ImplementedIn
[java] CertPathValidator.PKIX ImplementedIn
[java] Alg.Alias.Signature.SHA1/DSA
[java] CertPathValidator.PKIX
[java] Alg.Alias.KeyPairGenerator.1.2.840.10040.4.1
[java] CertStore.Collection ImplementedIn
[java] Alg.Alias.MessageDigest.SHA-1
[java] Provider.id info
[java] AlgorithmParameters.DSA ImplementedIn
[java] Signature.NONEwithDSA
[java] Alg.Alias.MessageDigest.SHA1
[java] CertStore.ru.sun.security.IndexedCollection
[java] CertPathBuilder.PKIX ImplementedIn
[java] KeyPairGenerator.DSA KeySize
[java] Alg.Alias.AlgorithmParameters.1.2.840.10040.4.1
[java] KeyFactory.DSA
[java] Alg.Alias.Signature.1.3.14.3.2.27
[java] Provider.id className
[java] CertStore.LDAP ImplementedIn
[java] SecureRandom.SHA1PRNG ImplementedIn
[java] AlgorithmParameterGenerator.DSA KeySize
[java] Alg.Alias.Signature.SHA-1/DSA
[java] SunRsaSign version 1.5
[java] Alg.Alias.Signature.OID.1.2.840.113549.1.1.4
[java] Alg.Alias.Signature.OID.1.2.840.113549.1.1.2
[java] Alg.Alias.KeyFactory.1.2.840.113549.1.1
[java] Signature.SHA512withRSA SupportedKeyClasses
[java] Provider.id version
[java] Signature.MD5withRSA SupportedKeyClasses
[java] Alg.Alias.Signature.1.2.840.113549.1.1.13
[java] KeyPairGenerator.RSA
[java] Alg.Alias.Signature.1.2.840.113549.1.1.12
[java] Alg.Alias.Signature.1.2.840.113549.1.1.11
[java] KeyFactory.RSA
[java] Alg.Alias.Signature.1.3.14.3.2.29
[java] Alg.Alias.KeyPairGenerator.OID.1.2.840.113549.1.1
[java] Signature.MD2withRSA
[java] Signature.SHA384withRSA
[java] Signature.MD5withRSA
[java] Provider.id info
[java] Signature.SHA1withRSA SupportedKeyClasses
[java] Signature.SHA1withRSA
[java] Alg.Alias.Signature.1.2.840.113549.1.1.5
[java] Signature.SHA256withRSA
[java] Alg.Alias.Signature.1.2.840.113549.1.1.4
[java] Provider.id className
[java] Alg.Alias.Signature.OID.1.2.840.113549.1.1.13
[java] Alg.Alias.Signature.OID.1.2.840.113549.1.1.12
[java] Alg.Alias.Signature.1.2.840.113549.1.1.2
[java] Alg.Alias.Signature.OID.1.2.840.113549.1.1.11
[java] Signature.MD2withRSA SupportedKeyClasses
[java] Provider.id name
[java] Alg.Alias.KeyFactory.OID.1.2.840.113549.1.1
[java] Signature.SHA384withRSA SupportedKeyClasses
[java] Signature.SHA512withRSA
[java] Signature.SHA256withRSA SupportedKeyClasses
[java] Alg.Alias.Signature.OID.1.2.840.113549.1.1.5
[java] Alg.Alias.KeyPairGenerator.1.2.840.113549.1.1
[java] SunJSSE version 1.5
[java] Alg.Alias.Signature.OID.1.2.840.113549.1.1.4
[java] Alg.Alias.KeyFactory.1.2.840.113549.1.1
[java] Alg.Alias.Signature.OID.1.2.840.113549.1.1.2
[java] Provider.id version
[java] TrustManagerFactory.SunX509
[java] KeyManagerFactory.NewSunX509
[java] KeyPairGenerator.RSA
[java] KeyStore.PKCS12
[java] SSLContext.SSLv3
[java] KeyFactory.RSA
[java] Alg.Alias.Signature.1.3.14.3.2.29
[java] Alg.Alias.TrustManagerFactory.X509
[java] Alg.Alias.KeyPairGenerator.OID.1.2.840.113549.1.1
[java] Signature.MD5andSHA1withRSA
[java] Signature.MD2withRSA
[java] Signature.MD5withRSA
[java] Provider.id info
[java] Signature.SHA1withRSA
[java] Alg.Alias.Signature.1.2.840.113549.1.1.5
[java] Alg.Alias.Signature.1.2.840.113549.1.1.4
[java] Provider.id className
[java] Alg.Alias.Signature.OID.1.3.14.3.2.29
[java] Alg.Alias.Signature.1.2.840.113549.1.1.2
[java] Provider.id name
[java] SSLContext.SSL
[java] SSLContext.TLS
[java] TrustManagerFactory.PKIX
[java] SSLContext.TLSv1
[java] Alg.Alias.KeyFactory.OID.1.2.840.113549.1.1
[java] KeyManagerFactory.SunX509
[java] Alg.Alias.TrustManagerFactory.SunPKIX
[java] Alg.Alias.TrustManagerFactory.X.509
[java] Alg.Alias.Signature.OID.1.2.840.113549.1.1.5
[java] Alg.Alias.KeyPairGenerator.1.2.840.113549.1.1
[java] SunJGSS version 1.0
[java] Provider.id info
[java] Provider.id className
[java] Provider.id version
[java] GssApiMechanism.1.2.840.113554.1.2.2
[java] Provider.id name
[java] SunSASL version 1.5
[java] Provider.id className
[java] SaslClientFactory.CRAM-MD5
[java] Provider.id version
[java] SaslClientFactory.EXTERNAL
[java] SaslClientFactory.DIGEST-MD5
[java] SaslClientFactory.PLAIN
[java] Provider.id name
[java] SaslClientFactory.GSSAPI
[java] SaslServerFactory.DIGEST-MD5
[java] SaslServerFactory.CRAM-MD5
[java] SaslServerFactory.GSSAPI
[java] Provider.id info
BUILD SUCCESSFUL
Total time: 2 seconds
*/
import java.security.Provider;
import java.security.Security;
import java.util.Enumeration;
public class MainClass {
public static void main(String[] args) throws Exception {
try {
Provider p[] = Security.getProviders();
for (int i = 0; i < p.length; i++) {
System.out.println(p[i]);
for (Enumeration e = p[i].keys(); e.hasMoreElements();)
System.out.println("\t" + e.nextElement());
}
} catch (Exception e) {
System.out.println(e);
}
}
}
List the available algorithm names for ciphers, key agreement, macs, message digests and signatures
/*
Ciphers:
None available.
KeyAgreeents:
None available.
Macs:
None available.
MessageDigests:
SHA-512
SHA1
MD2
SHA
SHA ImplementedIn
SHA-256
MD5 ImplementedIn
SHA-1
MD5
SHA-384
Signatures:
OID.1.2.840.10040.4.3
OID.1.2.840.113549.1.1.4
SHA384withRSA
1.3.14.3.2.29
SHA512withRSA SupportedKeyClasses
SHA/DSA
SHA1withDSA KeySize
NONEwithDSA SupportedKeyClasses
OID.1.2.840.113549.1.1.5
SHA512withRSA
MD5withRSA
DSS
OID.1.2.840.113549.1.1.11
SHA384withRSA SupportedKeyClasses
SHA1withRSA
MD5withRSA SupportedKeyClasses
NONEwithDSA
1.2.840.113549.1.1.4
MD5andSHA1withRSA
1.2.840.113549.1.1.11
OID.1.2.840.113549.1.1.13
1.3.14.3.2.27
1.2.840.10040.4.3
SHA256withRSA
MD2withRSA SupportedKeyClasses
1.2.840.113549.1.1.2
1.2.840.113549.1.1.12
RawDSA
SHA1withDSA
SHA1/DSA
MD2withRSA
1.3.14.3.2.13
SHAwithDSA
DSAWithSHA1
1.2.840.113549.1.1.13
OID.1.3.14.3.2.29
SHA1withDSA ImplementedIn
SHA256withRSA SupportedKeyClasses
SHA1withDSA SupportedKeyClasses
DSA
1.2.840.113549.1.1.5
SHA-1/DSA
SHA1withRSA SupportedKeyClasses
OID.1.2.840.113549.1.1.12
OID.1.2.840.113549.1.1.2
*/
import java.security.Provider;
import java.security.Security;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class ListAlgorithms {
public static void printSet(String setName, Set algorithms) {
System.out.println(setName + ":");
if (algorithms.isEmpty()) {
System.out.println(" None available.");
} else {
Iterator it = algorithms.iterator();
while (it.hasNext()) {
String name = (String) it.next();
System.out.println(" " + name);
}
}
}
public static void main(String[] args) {
Provider[] providers = Security.getProviders();
Set<String> ciphers = new HashSet<String>();
Set<String> keyAgreements = new HashSet<String>();
Set<String> macs = new HashSet<String>();
Set<String> messageDigests = new HashSet<String>();
Set<String> signatures = new HashSet<String>();
for (int i = 0; i != providers.length; i++) {
Iterator it = providers[i].keySet().iterator();
while (it.hasNext()) {
String entry = (String) it.next();
if (entry.startsWith("Alg.Alias.")) {
entry = entry.substring("Alg.Alias.".length());
}
if (entry.startsWith("Cipher.")) {
ciphers.add(entry.substring("Cipher.".length()));
} else if (entry.startsWith("KeyAgreement.")) {
keyAgreements.add(entry.substring("KeyAgreement.".length()));
} else if (entry.startsWith("Mac.")) {
macs.add(entry.substring("Mac.".length()));
} else if (entry.startsWith("MessageDigest.")) {
messageDigests.add(entry.substring("MessageDigest.".length()));
} else if (entry.startsWith("Signature.")) {
signatures.add(entry.substring("Signature.".length()));
}
}
}
printSet("Ciphers", ciphers);
printSet("KeyAgreeents", keyAgreements);
printSet("Macs", macs);
printSet("MessageDigests", messageDigests);
printSet("Signatures", signatures);
}
}