Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA: how to obtain keystore file for a certification (crt) file

HI All,

I have a .crt file and I need to get the associated keystore file. How to do so?

Is keytool is helpful in that?

Thanks.

like image 905
Muhammad Hewedy Avatar asked Oct 26 '10 10:10

Muhammad Hewedy


1 Answers

In JDK8 or higher:

Command below creates empty store and imports your certificate into the keystore:

keytool -import -alias alias -file cert_file.crt -keypass keypass -keystore yourkeystore.jks -storepass Hello1

In JDK7:

Older versions of JDK7 create non-empty keystore which then needs to be cleared. Below is how you do that.

Create store with temporary key inside:

keytool -genkey -alias temp -keystore yourkeystore.jks -storepass Hello1

Then delete existing entry:

keytool -delete -alias temp -keystore yourkeystore.jks -storepass Hello1 

Now you've got empty store. You can check that it's empty:

keytool -list -keystore yourkeystore.jks -storepass Hello1

Then import your certificate to the store:

keytool -import -alias alias -file cert_file.crt -keypass keypass -keystore yourkeystore.jks -storepass Hello1

And off you go!

like image 56
ruruskyi Avatar answered Oct 21 '22 21:10

ruruskyi