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

2

25

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.

Tybi answered 26/10, 2010 at 10:4 Comment(0)
A
53

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!

Appall answered 28/8, 2012 at 8:44 Comment(6)
why are trying to make it empty? I have keystore already which is not empty, will it make a difference to add another certificate rather than emptying it??Sewel
@Appall Hi, I find that you generate a .jks file. Is it possible to generate .keystore file?Fireworm
@Fireworm .jks and .keystore are essentially same thing, you can rename to .keystore if you want.Appall
Actually, you do not need to create an empty keystore first. If you use the last command only, it will create a keystore with just one trust entry for the imported certificate, given that the keystore does not yet exist.Trapani
Well, keytool has been changed in one of 1.7.0_1xx updates. So if you have one of those older versions of jdk7, you need all 4 commands. In jdk8 or higher you only need last line, agree.Appall
@Appall -keypass keyword is used for what purpose?Lockwood
S
-3

Yes, for eg.
keytool -genkey -alias duke -keypass dukekeypasswd from (http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/keytool.html)

Sirloin answered 26/10, 2010 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.