Sunteți pe pagina 1din 13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

Home About Contact Us Java JSF Spring Networking Application Server Facelets Polls

Tech Brainwave
A Road Map for Innovative Technologies

Step by step tutorial to create Keystore and Truststore file


Posted by giftsam Posted on Dec - 11 - 2010
Install Java Certificate SSL Java Tutorial Java File

Introduction Truststore and Keystore file will be used in the JSSE to provide secured transaction between the client and server. The keytool command is used to create the key store file which contains the public/private keys and then using keystore, Create a truststore file which contains only public keys. In this article, Let us learn how to create Truststore and Keystore file using 5 easy steps given below, 1. 2. 3. 4. 5. Generate a private key in keystore file Verifiy the newly created keystore file Export the certificate Import the certificate in to the truststore file Verifiy the newly created trust store file

Step 1 - Generate a private key in keystore file Java Keytool stores the keys and certificates in the keystore file. If you are a Windows user, the Keytool command should be executed in the Java bin directory. In my case the directory is C:\Program Files\Java\jdk1.6.0_12 and the following command should be executed,
1 k e y t o o lg e n k e y p a i ra l i a sc e r t i f i c a t e k e yk e y a l gR S Av a l i d i t y7k e y s t o r e k e y s t o r e . j k s

Once the preceding command is executed, you will be asked for the password, For this article, Let us give the password as techbrainwave. Once you give the password, you will be asking for the details as specified in the image below

www.techbrainwave.com/?p=953

1/13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

Next we should verify the newly created key store file. Step 2 Verifiy the newly created keystore file In Step2, Let us verify the newly created keystore.jks file using the following command, 1 k e y t o o ll i s tvk e y s t o r ek e y s t o r e . j k s After excuting the above command, you will get the details as specified in the image below,

Next we should export the certificate.


www.techbrainwave.com/?p=953 2/13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

Step 3 Export the certificate In step3, Either a self signed certificate or a commercial certificate from Verisign or other certificate authority should be exported. For exporting verisign certificates, the article Steps to configure Verisign certificate for Oracle Glassfish Server would be helpful. In this article, Let us see how to export a self signed certificate.

Metamucil: Ejercicios
metamucil.com.mx

Acceda y conozca los ejercicios para una vida ms saludable!

BEGIN CERTIFICATE MIICXjCCAccCBDwircEwDQYJKoZIhvcNAQEEBQAwdjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNB MRIwEAYDVQQHEwlQYWxvIEFsdG8xHzAdBgNVBAoTFlN1biBNaWNyb3N5c3RlbXMsIEluYy4xFjAU BgNVBAsTDUphdmEgU29mdHdhcmUxDTALBgNVBAMTBER1a2UwHhcNMDExMjIxMDMzNDI1WhcNMDEx MjI4MDMzNDI1WjB2MQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEjAQBgNVBAcTCVBhbG8gQWx0 bzEfMB0GA1UEChMWU3VuIE1pY3Jvc3lzdGVtcywgSW5jLjEWMBQGA1UECxMNSmF2YSBTb2Z0d2Fy ZTENMAsGA1UEAxMERHVrZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1loObJzNXsi5aSr8 N4XzDksD6GjTHFeqG9DUFXKEOQetfYXvA8F9uWtz8WInrqskLTNzwXgmNeWkoM7mrPpK6Rf5M3G1 NXtYzvxyi473Gh1h9k7tjJvqSVKO7E1oFkQYeUPYifxmjbSMVirWZgvo2UmA1c76oNK+NhoHJ4qj eCUCAwEAATANBgkqhkiG9w0BAQQFAAOBgQCRPoQYw9rWWvfLPQuPXowvFmuebsTc28qI7iFWm6BJ TT/qdmzti7B5MHOt9BeVEft3mMeBU0CS2guaBjDpGlf+zsK/UUi1w9C4mnwGDZzqY/NKKWtLxabZ 5M+4MAKLZ92ePPKGpobM2CPLfM8ap4IgAzCbBKd8+CMp8yFmifze9Q== END CERTIFICATE The preceding self signed certificate should be stored in a file named selfsignedcert.cer and then execute the following command, 1 k e y t o o le x p o r ta l i a sc e r t i f i c a t e k e yk e y s t o r ek e y s t o r e . j k sr f cf i l e s e l f s i g n e d c e r t . c e r After executing the above command, you will be asked for the password, Give the same password techbrainwave and you will get the details as specified in the image below,

Next we should import the certificate in to the truststore file. Step 4 Import the certificate in to the truststore file In step4, Let us import the certificate by executing the below command, 1 k e y t o o li m p o r ta l i a sc e r t i f i c a t e k e yf i l es e l f s i g n e d c e r t . c e r\ 2 k e y s t o r et r u s t s t o r e . j k s After executing the preceding command, Give the same password techbrainwave and you will get the details as specified in the image below,

www.techbrainwave.com/?p=953

3/13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

Next let us verify the newly created trust store file. Step 5 Verify the newly created trust store file In step5, verify the newly created trust store file by executing the following command, 1 k e y t o o ll i s tvk e y s t o r et r u s t s t o r e . j k s After executing the preceding command, you will get the details as specified in the image below,

Thats all folks. I hope this article clearly gives the Step by step tutorial to create simple Keystore and Truststore file. If you find this article is useful for you, dont forget to leave your valuable comments. Have a joyous code day.
SSL Certification Java Me Brain Wave Certificate Java

Categories: Java, JSSE, Networking, Remoting

33 Responses so far.
www.techbrainwave.com/?p=953 4/13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

1. Apache Mina SSL Configuration | Tech Brainwave says: December 13, 2010 at 11:01 pm [...] Truststore file. The Creation of these two files has been explained in the article Step by step tutorial to create Keystore and Truststore file . The factory classes used in the SSLContextGenerator class [...] Well-loved. Like or Dislike: 2. bojan says: April 18, 2011 at 9:10 pm hello, can i use keystore and truststore created by this tuturial for mutual certificate security on glassfish web server? i tried setting web service and web service client using self-signed certificate,and i get Validation of self signed certificate failed error. Well-loved. Like or Dislike: [Reply] 3. tactoth says: June 9, 2011 at 2:13 pm I would see this is a very useful article, very intuitive and informative. It really helps me much on understanding certificates, private/public keys, etc. Well-loved. Like or Dislike: [Reply] 4. tims says: June 17, 2011 at 9:58 pm It is not clear to me when the truststore file is created.
2 1 9 2 14 2 46 2

[Reply]

giftsam Reply:
June 18th, 2011 at 6:57 pm

In step4, the truststore file is created. The truststore file contains only public keys. Well-loved. Like or Dislike: [Reply] 5. Deepak Ku Patel says: June 28, 2011 at 5:00 pm Its very good & clearly mention the right steps. Thanks
www.techbrainwave.com/?p=953 5/13
6 0

23/05/13
2 0

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

[Reply] 6. Rishu Aggarwal says: July 26, 2011 at 1:46 pm Nice work techbrainwave !! very handful info..
2 0

[Reply] 7. Resources about PKI infrastructure + SSL/TLS, standards, tools(keytool, openssl) | Tsetso's Stuff says: July 27, 2011 at 9:29 pm [...] 6.1) Generating a KeyStore and TrustStore (Oracle documentation) > (link) 6.2) JKS and JCEKS keystores > (link) JCEKS keystore (Oracle documentation) > (link) 6.3) Creating a key and trust store with JSSE in Java( client and server) > (link) 6.4) keystore vs. truststore (victor-jans blog) > (link) 6.5) Step by step tutorial to create Keystore and Truststore file (techbrainwaves website) > (link) [...]
0 0

8.

Adam Mauger says: August 31, 2011 at 9:59 am The preceding self signed certificate should be stored in a file named selfsignedcert.cer and then execute the following command, keytool -export -alias certificatekey -keystore keystore.jks -rfc -file selfsignedcert.cer Er, selfsignedcert.cer is just overwritten.
1 0

[Reply] 9. sureshkumar Chinnaraj says: September 16, 2011 at 5:47 pm This tutorial explains very well about signing jar files thanks a lot!!!
0 1

[Reply] 10. Narendra says: September 20, 2011 at 8:25 pm Can I copy this file somewhere else and use it ?
0 0

[Reply]
www.techbrainwave.com/?p=953 6/13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

giftsam Reply:
September 21st, 2011 at 2:55 pm

Narendra, Which file you want to copy?


0 0

[Reply] 11. Ram says: September 22, 2011 at 7:30 pm Really useful information on keystore and truststore with simple explaination
2 0

[Reply] 12. Ron says: October 24, 2011 at 11:33 am Thanks for the great tutorial.. I want to use the certificate and truststore in my client server application. How can I use it. I am using JSSE. Just wondering how to use generated certificate and truststore in my application. Thanks
0 1

[Reply] 13. Nurlan says: December 5, 2011 at 2:37 pm I need a keytool command which imports an existing private key(.pem) into the keystore.jks. I tried keytool -import -trustcacerts -file mypem.pem -alias CA_ALIAS -keystore keystore.jks but it gave me the following error keytool error: java.lang.Exception: Input not an X.509 certificate Can anybody help?? Thanks in advance. Nurlan
2 0

[Reply]

Madhurima Reply:
May 21st, 2012 at 6:39 pm
www.techbrainwave.com/?p=953 7/13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

Hi All, I am also facing the same issue ,please help me. Thanks, Madhurima
0 0

[Reply]

J Brun Reply:
February 19th, 2013 at 3:30 am

There is NO keytool command that does this Nurlan. You will have to use another tool or script to convert everything into one keystore file. You can create a keystore file (with your private key) and a truststore file (with your public cert), as described above and configure your tomcat or java application to use both files.
0 0

[Reply] 14. Jas says: December 8, 2011 at 2:37 pm step by step explanation helped me a lot in understanding certificate generation and keystore generation. Great Tutorial Well-loved. Like or Dislike: [Reply] 15. ammy says: December 16, 2011 at 7:52 am wonderful!!! thanks for such a detail article.
1 0 5 0

[Reply] 16. Eknath says: January 31, 2012 at 10:04 pm Nice Tutorial.. Helped me a lot. and saved time. Thanks a Ton !!!!!!!!!!!!
1 0

[Reply] 17. Naidu says:


8/13

www.techbrainwave.com/?p=953

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

February 1, 2012 at 4:17 pm How to create the private key and public key for a self signed certificate ?
0 0

[Reply] 18. ahmet says: March 6, 2012 at 9:43 pm thank you very much.. perfect tutorial.. Well-loved. Like or Dislike: [Reply] 19. ratish says: March 16, 2012 at 4:09 pm awesome man
1 0 4 0

[Reply] 20. SSL Handshaking Using Self-Signed Certs and SSLEngine (JSSE) | PHP Developer Resource says: May 23, 2012 at 6:23 pm [...] The keystore and truststore referenced in the code snippit above were created using the following tutorial: http://www.techbrainwave.com/?p=953 [...]
0 0

21.

john cena says: July 9, 2012 at 11:46 am after creating truststore.jks what is the next step?
0 0

[Reply] 22. Pankaj says: September 27, 2012 at 1:20 pm This tutorial explains very well creating keystore and trusstore. very thanks..
0 0

[Reply] 23. Karthik says:


9/13

www.techbrainwave.com/?p=953

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

October 10, 2012 at 4:57 pm This link was very useful. Thank you.
0 0

[Reply] 24. thiru says: October 23, 2012 at 2:38 pm good one. thanks.
0 0

[Reply] 25. mahesh says: December 14, 2012 at 12:55 pm wonderful and excellent
1 0

[Reply] 26. Trev Thorpe says: December 18, 2012 at 12:56 am Very useful link, cleared up an issue I was having. Thanks, Trev
1 0

[Reply] 27. Pritam says: January 21, 2013 at 9:02 pm Gr8 information, helpful in implementation, and provide good guidace for development.
1 0

[Reply] 28. Lalit says: January 29, 2013 at 12:47 am This is really great tutorial. Thanks buddy.
1 0

www.techbrainwave.com/?p=953

10/13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

[Reply] 29. Solly says: February 12, 2013 at 7:12 pm Before I read this article, I was clueless about Keystore and trustore files. Simple straight to the point article..thanks ma.
1 0

[Reply] Name (required) Mail (required) Website

Submit

Notify me of follow-up comments via e-mail

Categories
Apache Mina Application Server Design Pattern Excel Facelets Internet Explorer8 Java Java EE JDBC JQuery JSF JSSE Netbeans
www.techbrainwave.com/?p=953 11/13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

Networking Polls Primefaces Remoting Richfaces Seam Servlets Spring Tomcat

Recent Posts
Java Factory Design Pattern Tomcat Native Library (APR) Installation Apache Mina SSL Configuration Step by step tutorial to create Keystore and Truststore file Apache Mina Simple client/Server Application What web application test tool do you use? Spring 3.0 AOP Advice Tomcat Production Server Performance Tuning Java based container configuration in Spring 3.0 Spring 3.0 + JPA 2.0 using plain API DAOs

Top Posts
Java code to Read an Excel file using POI Step by step tutorial to create Keystore and Truststore file Step by step tutorial to setup Primefaces in Netbeans Java code to write to an Excel file using POI Exception Handling in JSF

Recent Comments
Rita on Java code to Read an Excel file using POI J Brun on Step by step tutorial to create Keystore and Truststore file Ranjith g on Java code to Read an Excel file using POI Ranjith on Java code to Read an Excel file using POI Solly on Step by step tutorial to create Keystore and Truststore file

Archives
July 2011
www.techbrainwave.com/?p=953 12/13

23/05/13

Step by step tutorial to create Keystore and Truststore file | Tech Brainwave

December 2010 November 2010 July 2010 June 2010 December 2009 November 2009 October 2009 September 2009

Meta
Log in Entries RSS Comments RSS WordPress.org Copyright 2013 Tech Brainwave - A Road Map for Innovative Technologies.

www.techbrainwave.com/?p=953

13/13

S-ar putea să vă placă și