This is a really odd error. On two machines, the code is running perfectly. I just set this up on a brand new machine and this isn't working. I'm getting the following error when running the script;
java.lang.RuntimeException: java.security.NoSuchAlgorithmException: PBKDF2WithHmacSHA512 SecretKeyFactory not available
The line of code that is causing the error is;
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance( "PBKDF2WithHmacSHA512" );
Using JDK 1.7.0
The code is all compiling correctly, it is just failing at run time on this line. I have a feeling this is some how related to a JAR file that is different or a JDK that is slightly different, but after checking everything across the different machines, everything looks identical.
Thoughts?
Support for PBKDF2WithHmacSHA512 was added in Java 8, it is not available in Java 7 by default (Java 7 itself only supports PBKDF2WithHmacSHA1).
Compare:
SecretKeyFactory
Algorithms for Java 7
PBKDF2WithHmacSHA1
Constructs secret keys using the Password-Based Key Derivation Function function found in PKCS #5 v2.0.
SecretKeyFactory
Algorithms for Java 8
PBKDF2With<prf>
Password-based key-derivation algorithm found in PKCS #5 2.0 using the specified pseudo-random function (<prf>
). Example: PBKDF2WithHmacSHA256.
So you need to either upgrade to Java 8, or downgrade to PBKDF2WithHmacSHA1, or check if there is a JCE provider that provides PBKDF2WithHmacSHA512 for Java 7 (for example, Bouncy Castle).
If your code is running ok on another machine with Java 7, then check if lib/ext
of that Java install contains additional libraries, for example Bouncy Castle has a JCE provider that supports PBKDF2WithHmacSHA512. In that case, you will need to include that same library in the Java install of the other machine.
I was getting the same error because I was running a unit test with PowerMockRunner
, i.e.:
@RunWith(PowerMockRunner.class)
public class MyTest {
//...
}
Removing @RunWith(PowerMockRunner.class)
solved the issue for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With