1

I am trying to generate a private key with a password using a SecretKeyFactory and when I start the program I have a runtime exception that says algorithm not available. But in others PCs it works fine! Any help ?

private static void generatePrivateKey(String pwd) {

    try {
        PBEKeySpec keySpec = new PBEKeySpec(pwd.toCharArray());
        SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithHmacSHA256AndAES_128");
        PRIVATE_KEY = kf.generateSecret(keySpec);
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        e.printStackTrace();
    }
}

Runtime exception: enter image description here

Dariko77
  • 141
  • 1
  • 8
  • 1
    do you know the specific JRE that the other PCs have that do have the PBEWithHmacSHA256AndAES_128? You are currently using JRE 1.8.0_121 and perhaps it's not supported for that environment. Try this http://stackoverflow.com/questions/9333504/how-can-i-list-the-available-cipher-algorithms to list the available algorithms – RAZ_Muh_Taz Mar 28 '17 at 23:20
  • Yes the other PC have JRE 1.8.0_121 and it runs very well – Dariko77 Mar 29 '17 at 07:36

1 Answers1

0

There are multiple possibilities:

  1. May be the JRE has been modified
  2. An additional crypto provider has been installed. As you don't specify the provider in your ScretKeyFactory creation you don't know which provider is used. In Oracle JRE the algorithm you want is provided by the SunJCE. hence the following should work: SecretKeyFactory.getInstance("PBEWithHmacSHA256AndAES_128", "SunJCE");
Robert
  • 39,162
  • 17
  • 99
  • 152