Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a key with keytool, in a non-interactive way

When I'm using:

"C:\Program Files\Java\jdk1.8.0_151\bin\keytool.exe" -genkey 
     -v -keystore my.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias app

then an interactive process begins which asks name, password, etc.

Is there a way to have a non-interactive generation of keys, where parameters are directly in the command line parameters?

like image 955
Basj Avatar asked Apr 21 '18 18:04

Basj


People also ask

What is used to generate a keystore and key?

Use the standard JDK keytool utility to generate and load a new key and a self-signed certificate. When prompted, supply the certificate and password information. Doing so protects the keystore file and the keys within in the file.

What does Keytool Exportcert do?

Use the -exportcert command to read a certificate from the keystore that is associated with -alias alias and store it in the -file file. When a file is not specified, the certificate is output to stdout . By default, the certificate is output in binary encoding.


1 Answers

This works:

keytool -genkey -keystore my.keystore -keyalg RSA -keysize 2048 \
        -validity 10000 -alias app -dname "cn=Unknown, ou=Unknown, o=Unknown, c=Unknown" \
        -storepass abcdef12 -keypass abcdef12
like image 142
Basj Avatar answered Sep 30 '22 07:09

Basj