keytool error: java.lang.Exception: The -keyalg must be specified

Viewed 770

I am trying to create a key pair and storing them in a key store from the Windows command line prompt (using Windows 10 JDK 14). Here is the command I am typing:

keytool -genkey -alias chris -keystore chirskeystore

First, system prompts me for a password then re-enter the password and finally, it returns with the following error:

keytool error: java.lang.Exception: The -keyalg option must be specified.

The command is directly from the Oracle tutorial on java security: https://docs.oracle.com/javase/tutorial/security/toolfilex/step2.html
Searching for the -keyalg or the error led to nowhere. Any insight will be great.

Thanks.

2 Answers

I get the exact same error with Adoptium Temurin Java version 17.0.3 with command:

keytool -genkeypair -alias chris -keystore chirskeystore \
    -storepass "MyPassword123" -dname "CN=MY_FQDN"

The fix for me is to be explicit about -keyalg value:

keytool -genkeypair -alias chris -keystore chirskeystore \
    -storepass "MyPassword123" -dname "CN=MY_FQDN" \
    -keyalg dsa

Note -genkey from initial question is an alias for -genkeypair.

And option -keyalg had before default value dsa for -genkey. But now it's required to specify it. Oracle should update their tutorial on java security.

One more thing: the latest documentation of -keyalg can be find here on oracle.com

Well it turned out that keytool in the JRE\bin is more recent 6/6/2020 than the one in the JDK\bin 5/4/2020. The keytool in the JRE\bin works fine.

Related