DEV Community

Cover image for Useful Java KeyStore Keytool Commands
Şammas Çölkesen
Şammas Çölkesen

Posted on

Useful Java KeyStore Keytool Commands

Create Self-Signed Sertifika and KeyStore

>keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 720

Enter fullscreen mode Exit fullscreen mode

Create CSR Certificate

>keytool -certreq -alias mydomain -keystore keystore.jks -storepass password -file mydomain.csr

Enter fullscreen mode Exit fullscreen mode

Delete Certificate from KeyStore

>keytool -delete -alias mydomain -keystore keystore.jks -storepass password
Enter fullscreen mode Exit fullscreen mode

Add Signed Primary Certificate to KeyStore

>keytool -import -trustcacerts -alias mydomain -file mycrt.crt -keystore keystore.jks
Enter fullscreen mode Exit fullscreen mode

Change KeyStore Password

>keytool -storepasswd -new new_storepass -keystore keystore.jks
Enter fullscreen mode Exit fullscreen mode

List KeyStore

>/JAVA_HOME/jre/bin/keytool -list -keystore KeyStore -storepass password
Enter fullscreen mode Exit fullscreen mode

Create Private Key

>keytool -genkey -alias KeyToolAlias -keystore privateKey.store

# Enter keystore password:
>1234

# What is your first and last name?
>John Smith
# What is the name of your organizational unit?
>Sowtware Development
# What is the name of your organization?
>dev.to
# What is the name of your City or Locality?
>Istanbul
# What is the name of your State or Province?
>Besiktas
# What is the two-letter country code for this unit?
>TR
# Is your infos correct?
>yes
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
me_priya profile image
Priya Mervana

@kavanozkafa The article is well-written, but I believe it would benefit from including a more comprehensive exploration of Java Keytool KeyStore Commands from here.

Collapse
 
ssl_wiki profile image
SSLWiki • Edited

@kavanozkafa Thanks for sharing this nice commands. Here're more Java Keystore Keytool Commands - sslwiki.org/java-keytool-keystore-...