I recently wanted to know which hash functions were available to Java in a given machine, so I cooked up a little command line tool for that. Maybe this could be useful to others so I posted it here.
Java hash functions are implemented as a MessageDigest object, which you can’t instance directly but rather get an instance through the MessageDigest.getInstance() static method. It takes as it’s only argument a string with the name of the algorithm – but I couldn’t find an easy way to enumerate all available algorithms.
After a little googling I found this code example at Example Depot to do it programatically. Since results may vary from one installation of Java to the next, a command line tool would have been more useful to me, but I don’t know of any. (If you do, let me know!)
Anyway, I wrapped the code in a very simple Main function and compiled it using Eclipse. I called this little tool “ListServices” because I didn’t feel like thinking of a catchy name.😛
By default this tool lists all available cryptographic providers, but you can specify just the ones you need (in the example below, we type MessageDigest to get just the hashing algorithms):
$ java -jar ListServices.jar KeyFactory: 1.2.840.1135126.96.36.199 OID.1.2.840.113549.1.1 1.2.840.113549.1.1 OID.1.2.840.1135188.8.131.52 184.108.40.206.2.12 DSA DiffieHellman RSA DH 1.2.840.10040.4.1 TransformService: INCLUSIVE_WITH_COMMENTS ENVELOPED (... output omitted for brevity ...) $ java -jar ListProviders.jar MessageDigest MessageDigest: SHA-256 SHA-512 SHA SHA-384 SHA1 MD5 SHA-1 MD2 $
Update: Added source code to Github.