keytool able to generate a secret key, since Java 6 c is a genseckey command . Here is an excerpt from the Java 6 keytool documentation :
-genseckey {-alias alias} {-keyalg keyalg} {-keysize keysize} [-keypass keypass] {-storetype storetype} {-keystore keystore} [-storepass storepass] {-providerClass provider_class_name {-providerArg provider_arg}} {-v} {-protected} {-Jjavaoption}
Creates a private key and stores it in a new KeyStore.SecretKeyEntry identified by an alias.
keyalg defines the algorithm that will be used to generate the secret key, and keyize determines the size of the key to be generated. keypass is the password used to protect the private key. If no password is specified, the user will be prompted to enter it. If you press RETURN at the invitation, the key password will be set to the same password as for the keystore. The key length must be at least 6 characters.
So the following command will create a new 128 bit AES key
keytool -genseckey -alias mykey -keyalg AES -keysize 128 \ -storetype jceks -keystore mykeystore.jks
The keytool command has a typo that hides help information about -genseckey :
% keytool -help [...] -genkeypair [-v] [-protected] [-alias <alias>] [-keyalg <keyalg>] [-keysize <taille_clรฉ>] [-sigalg <sigalg>] [-dname <nomd>] [-validity <joursVal>] [-keypass <mot_passe_clรฉ>] [-keystore <keystore>] [-storepass <mot_passe_store>] [-storetype <storetype>] [-providername <name>] [-providerclass <provider_class_name> [-providerarg <arg>]] ... [-providerpath <pathlist>] -genkeypair [-v] [-protected] [-alias <alias>] [-keypass <keypass>] [-keyalg <keyalg>] [-keysize <taille_clรฉ>] [-keystore <keystore>] [-storepass <mot_passe_store>] [-storetype <storetype>] [-providername <name>] [-providerclass <provider_class_name> [-providerarg <arg>]] ... [-providerpath <pathlist>]
The -genkeypair command appears twice. In fact, the second -genkeypair should read -genseckey . That is why I did not notice the command.
I ran into this typo error with Java 1.6.0_26. I checked with the latest version of Java 6 (1.6.0_31) and it has the same problem. I also checked with the latest version of Java 7 and fixed the problem with the documentation:
% java -version java version "1.7.0_03" Java(TM) SE Runtime Environment (build 1.7.0_03-b04) Java HotSpot(TM) Server VM (build 22.1-b02, mixed mode) % keytool -help [...] -genkeypair Generates a key pair -genseckey Generates a secret key [...]
source share