Skip to content

Instantly share code, notes, and snippets.

@laszlomiklosik
Last active December 21, 2015 08:28
Show Gist options
  • Save laszlomiklosik/6277886 to your computer and use it in GitHub Desktop.
Save laszlomiklosik/6277886 to your computer and use it in GitHub Desktop.
keytool frequently used commands
1. when importing public key, a .cer file needs to be created and the X509 data must be entered between these:
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
2. import a public key:
keytool -keystore mykeystore.jks -storepass mykeystorepass -import -noprompt -trustcacerts -alias myserveralias -file public.cer
3. generate self signed x509 certificate:
keytool -genkey -alias clientkey -keyalg RSA -sigalg SHA1withRSA -keypass clientpass -storepass mykeystorepass -keystore mykeystore.jks -validity 365 -dname "cn=clientuser"
4. export a public cert from a keystore
keytool -exportcert -alias clientkey -keypass mykeypass -keystore mykeystore.jks -storepass mykeystorepass -rfc -file public.cer
5. list keystore contents
keytool --list -keystore mykeystore.jks -storepass mykeystorepass
@laszlomiklosik
Copy link
Author

if you want a longer validity period just add
-validity 730
to the first command, where 730 in the validity period in days starting from now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment