25
votes

I have a key store file cacerts under jre/lib/security in which i added a Certicate by using the import command.

There are more than 50 certificates in my keystore. How do i find the alias name of the last imported certificate in the keystore. I want to delete the last added certificate for which i need the alias name. Kindly help.

4

4 Answers

48
votes

You can list all certificates in the keystore like

on Linux

keytool -list -v -keystore keystore.jks | grep "Alias name\|Creation date"

on Windows

keytool -list -v -keystore keystore.jks | findstr "Alias Creation"
4
votes

Have you tried listing all certificates.

keytool -list -v -keystore keys.store

It may be in the order they were added.

Also if you added the certificate via command prompt or terminal check history.

2
votes

You can use java.security.KeyStore to load your keystore and use aliases() method to get Enumaration of all alias names in your keystore file.

java security.Keystore java doc

0
votes

you can use this command for find added certificate by alias:

keytool -list -v -keystore keystore.jks -alias mydomain