OpenJDK 1.6 and SecureRandom/KeyGenerator (what is available?)

6.9k views Asked by At

All of the following result in "java.security.NoSuchAlgorithmException: SHA not SecureRandom available" (or similar).

SecureRandom prng = SecureRandom.getInstance("SHA256");
SecureRandom prng = SecureRandom.getInstance("SHA-256");
SecureRandom prng = SecureRandom.getInstance("SHA1");
SecureRandom prng = SecureRandom.getInstance("SHA-1");
SecureRandom prng = SecureRandom.getInstance("SHA");

Similar for the following ("java.security.NoSuchAlgorithmException: SHA KeyGenerator not available"):

KeyGenerator kgen = KeyGenerator.getInstance("SHA256");
KeyGenerator kgen = KeyGenerator.getInstance("SHA-256");
KeyGenerator kgen = KeyGenerator.getInstance("SHA1");
KeyGenerator kgen = KeyGenerator.getInstance("SHA-1");
KeyGenerator kgen = KeyGenerator.getInstance("SHA");

What generators are available in OpenJDK? According to Standard Algorithm Names, it looks like the SHA family should be available (at least for SecureRandom).

Sorry for the lame Java question. I'm a Crypto++ and OpenSSL kind of guy, and Google is returning a lot of noise. I'm working in Eclipse if it matters.

Jeff

2

There are 2 answers

4
Martin Paljak On BEST ANSWER

KeyGenerator has documentation. SHA* is a hash, not an encryption algorihtm. Using SHA* in the context of KeyGenerator makes little to no sense.

For SecureRandom (which, by the way, also has documentation) you are better off not specifying an algorithm unless you have specific requirements and you know what you are doing (like you know the provider you are trying to use)

The only connection I can come up with is the fact that the Sun JCE SecureRandom actually uses SHA1PRNG underneath.

1
bilash.saha On

I think this should help you

http://www.java2s.com/Code/Java/Security/ListAllProviderAndItsAlgorithms.htm

Check it. Best of luck!