{"id":62416,"date":"2020-08-27T06:57:46","date_gmt":"2020-08-27T06:57:46","guid":{"rendered":"https:\/\/www.baeldung.com\/?p=86258"},"modified":"2020-08-27T06:57:46","modified_gmt":"2020-08-27T06:57:46","slug":"introduction-to-keytool","status":"publish","type":"post","link":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/2020\/08\/27\/introduction-to-keytool\/","title":{"rendered":"Introduction to keytool"},"content":{"rendered":"<p class=\"syndicated-attribution\"><meta name= \\\"keywords \\\" content= \\\"\u96fb\u5b50\u8a08\u7b97\u6a5f, \u6559\u80b2, IT \u96fb\u8166\u73ed,\u96fb\u8166\u88dc\u7fd2\uff0c \u96fb\u8166\u73ed\uff0c \u5bb6\u6559\uff0c \u79c1\u4eba\u8001\u5e2b\uff0c \u8cc7\u8a0a\u6280\u8853\uff0c \u7a0b\u5e8f\u8a2d\u8a08\uff0c \u96fb\u5b50\u8a08\u7b97\u6a5f\uff0c \u904a\u6232\uff0c \u860b\u679c\uff0c \u96fb\u5f71\uff0c \u8a08\u7b97\u6a5f\uff0c\u7de8\u78bc\uff0c Java\uff0c C\/C++\uff0c JavaScript\uff0c PHP\uff0c HTML\uff0c CSS\uff0c MySQL\uff0c mobile\uff0c Android\uff0c \u52d5\u6f2b\uff0c Python\uff0c teacher\uff0c \u88dc\u7fd2\uff0c \u96fb\u8166\u88dc\u7fd2 \u8cc7\u8a0a, \u7535\u5b50\u8ba1\u7b97\u673a, IT ,Game, apple, movie, Computer,student,Java,\u6559\u80b2, ,\u5b66\u751f, \u5b66\u4e60, learn, \u6559\u5b66,  Android, apple,anime, animation, \u4fe1\u606f\u6280\u672f, \u7a0b\u5e8f\u8bbe\u8ba1, \u79fb\u52a8\u7535\u8bdd, \u8cc7\u8a0a\u79d1\u6280,Game, Jeu, Juego,Call Of Duty ,\u4f7f\u547d\u53ec\u559a , \u6e38\u620f, \u7535\u5b50\u6e38\u620f,, \u591a\u4eba\u7535\u5b50\u6e38\u620f, \u7f51\u7edc\u6e38\u620f\uff0conline\uff0conline game, \u624b\u673a\u6e38\u620f, mobile \\\"><\/p>\n<h2  data-id=\"overview\"><strong>1. Overview<\/strong><\/h2>\n<div class=\"bd-anchor\" id=\"overview\"><\/div>\n<p>In this short tutorial, we&#8217;re going to introduce the <em><a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/tools\/unix\/keytool.html\">keytool<\/a><\/em> command. We&#8217;ll learn how to use <em>keytool<\/em> to create a new certificate and check the information for that certificate.<\/p>\n<h2  data-id=\"keytool\"><strong>2. What Is <em>keytool<\/em>?<\/strong><\/h2>\n<div class=\"bd-anchor\" id=\"keytool\"><\/div>\n<p>Java includes the <em>keytool<\/em> utility in its releases. We use it to<strong> manage<\/strong><strong>\u00a0keys and certificates<\/strong> and store them in a keystore. The <em>keytool<\/em> command allows us to create self-signed certificates and show information about the keystore.<\/p>\n<p>In the following sections, we&#8217;re going to go through different functionalities of this utility.<\/p>\n<h2  data-id=\"cert\"><strong>3. Creating a Self-Signed Certificate<\/strong><\/h2>\n<div class=\"bd-anchor\" id=\"cert\"><\/div>\n<p>First of all, let&#8217;s create a self-signed certificate that could be used to establish secure communication between projects in our development environment, for example.<\/p>\n<p>In order to <strong>generate the certificate<\/strong>, we&#8217;re going to open a command-line prompt and use <em>keytool<\/em> command with the <em>-genkeypair<\/em> option:<\/p>\n<pre><code class=\"language-shell\">keytool -genkeypair -alias &lt;alias&gt; -keypass &lt;keypass&gt; -validity &lt;validity&gt; -storepass &lt;storepass&gt;<\/code><\/pre>\n<p>Let&#8217;s learn more about each of these parameters:<\/p>\n<ul>\n<li><em>alias<\/em> &#8211; the name for our certificate<\/li>\n<li><em>keypass<\/em> &#8211; the password of the certificate. We&#8217;ll need\u00a0this password to have access to the private key of our certificate<\/li>\n<li><em>validity<\/em> &#8211; the time (in days) of the validity of our certificate<\/li>\n<li><em>storepass<\/em> &#8211; the password for the keystore. This will be the password of the keystore if the store doesn&#8217;t exist<\/li>\n<\/ul>\n<p>For example, let&#8217;s generate a certificate named <em>&#8220;cert1&#8221;<\/em> that has a private key of <em>&#8220;pass123&#8221;<\/em> and is valid for one year. We&#8217;ll also specify <em>&#8220;stpass123&#8221;<\/em> as the keystore password:<\/p>\n<pre><code class=\"language-shell\">keytool -genkeypair -alias cert1 -keypass pass123 -validity 365 -storepass stpass123<\/code><\/pre>\n<p>After executing the command, it&#8217;ll ask for some information that we&#8217;ll need to provide:<\/p>\n<pre><code class=\"language-shell\">What is your first and last name?\r\n  [Unknown]:  Name\r\nWhat is the name of your organizational unit?\r\n  [Unknown]:  Unit\r\nWhat is the name of your organization?\r\n  [Unknown]:  Company\r\nWhat is the name of your City or Locality?\r\n  [Unknown]:  City\r\nWhat is the name of your State or Province?\r\n  [Unknown]:  State\r\nWhat is the two-letter country code for this unit?\r\n  [Unknown]:  US\r\nIs CN=Name, OU=Unit, O=Company, L=City, ST=State, C=US correct?\r\n  [no]:  yes<\/code><\/pre>\n<p>As mentioned, if we haven&#8217;t created the keystore before, creating this certificate will create it automatically.<\/p>\n<p>We could also execute the <em>-genkeypair<\/em> option without parameters. If we don&#8217;t provide them in the command line and they&#8217;re mandatory, we&#8217;ll be prompted for them.<\/p>\n<p><strong>Note that it&#8217;s generally advised not to provide the passwords (<em>-keypass<\/em> or<em> -storepass<\/em>) on the command line in production environments<\/strong>.<\/p>\n<h2  data-id=\"list\"><strong>4. Listing Certificates in the Keystore<\/strong><\/h2>\n<div class=\"bd-anchor\" id=\"list\"><\/div>\n<p>Next, we&#8217;re going to learn how to <strong>view the certificates<\/strong> that are stored in our keystore. For this purpose, we&#8217;ll use the <em>-list<\/em> option:<\/p>\n<pre><code class=\"language-shell\">keytool -list -storepass &lt;storepass&gt; <\/code><\/pre>\n<p>The output for the executed command will show the certificate that we&#8217;ve created:<\/p>\n<pre><code class=\"language-shell\">Keystore type: JKS\r\nKeystore provider: SUN\r\nYour keystore contains 1 entry\r\ncert1, 02-ago-2020, PrivateKeyEntry, \r\nCertificate fingerprint (SHA1): 0B:3F:98:2E:A4:F7:33:6E:C4:2E:29:72:A7:17:E0:F5:22:45:08:2F<\/code><\/pre>\n<p>If we want to get the<strong> information for a concrete certificate<\/strong>, we just need to include the<em>\u00a0-alias<\/em> option to our command. To get further information than provided by default, we&#8217;ll also add the <em>-v<\/em> (verbose) option:<\/p>\n<pre><code class=\"language-shell\">keytool -list -v -alias &lt;alias&gt; -storepass &lt;storepass&gt; <\/code><\/pre>\n<p>This will provide us all the information related to the requested certificate:<\/p>\n<pre><code class=\"language-shell\">Alias name: cert1\r\nCreation date: 02-ago-2020\r\nEntry type: PrivateKeyEntry\r\nCertificate chain length: 1\r\nCertificate[1]:\r\nOwner: CN=Name, OU=Unit, O=Company, L=City, ST=State, C=US\r\nIssuer: CN=Name, OU=Unit, O=Company, L=City, ST=State, C=US\r\nSerial number: 11d34890\r\nValid from: Sun Aug 02 20:25:14 CEST 2020 until: Mon Aug 02 20:25:14 CEST 2021\r\nCertificate fingerprints:\r\n\t MD5:  16:F8:9B:DF:2C:2F:31:F0:85:9C:70:C3:56:66:59:46\r\n\t SHA1: 0B:3F:98:2E:A4:F7:33:6E:C4:2E:29:72:A7:17:E0:F5:22:45:08:2F\r\n\t SHA256: 8C:B0:39:9F:A4:43:E2:D1:57:4A:6A:97:E9:B1:51:38:82:0F:07:F6:9E:CE:A9:AB:2E:92:52:7A:7E:98:2D:CA\r\nSignature algorithm name: SHA256withDSA\r\nSubject Public Key Algorithm: 2048-bit DSA key\r\nVersion: 3\r\nExtensions: \r\n#1: ObjectId: 2.5.29.14 Criticality=false\r\nSubjectKeyIdentifier [\r\nKeyIdentifier [\r\n0000: A1 3E DD 9A FB C0 9F 5D   B5 BE 2E EC E2 87 CD 45  .&gt;.....].......E\r\n0010: FE 0B D7 55                                        ...U\r\n]\r\n]<\/code><\/pre>\n<h2  data-id=\"conclusion\"><strong>5. Other Features<\/strong><\/h2>\n<div class=\"bd-anchor\" id=\"conclusion\"><\/div>\n<p>Apart from the functionalities that we&#8217;ve already seen, there are many <a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/tools\/unix\/keytool.html\">additional features<\/a> available in this tool.<\/p>\n<p>For example, we can <strong>delete the certificate<\/strong> we created from the keystore:<\/p>\n<pre><code class=\"language-shell\">keytool -delete -alias &lt;alias&gt; -storepass &lt;storepass&gt;<\/code><\/pre>\n<p>Another example is that we will even be able to <strong>change the alias of a certificate<\/strong>:<\/p>\n<pre><code class=\"language-shell\">keytool -changealias -alias &lt;alias&gt; -destalias &lt;new_alias&gt; -keypass &lt;keypass&gt; -storepass &lt;storepass&gt;<\/code><\/pre>\n<p>Finally, to get more information about the tool, we can <strong>ask for help<\/strong> through the command line:<\/p>\n<pre><code class=\"language-shell\">keytool -help<\/code><\/pre>\n<h2  data-id=\"conclusion-1\"><strong>6. Conclusion<\/strong><\/h2>\n<div class=\"bd-anchor\" id=\"conclusion-1\"><\/div>\n<p>In this quick tutorial, we&#8217;ve learned a bit about the <em>keytool<\/em> utility. We&#8217;ve also learned to use some basic features included in this tool.<\/p>\n<p><Img align=\"left\" border=\"0\" height=\"1\" width=\"1\" alt=\"\" style=\"border:0;float:left;margin:0;padding:0;width:1px!important;height:1px!important;\" hspace=\"0\" src=\"https:\/\/feeds.feedblitz.com\/~\/i\/634570196\/0\/baeldung\"><\/p>\n<div style=\"clear:both;padding-top:0.2em;\"><a title=\"Like on Facebook\" href=\"https:\/\/feeds.feedblitz.com\/_\/28\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/fblike20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Share on Google+\" href=\"https:\/\/feeds.feedblitz.com\/_\/30\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/googleplus20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Pin it!\" href=\"https:\/\/feeds.feedblitz.com\/_\/29\/634570196\/baeldung,\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/pinterest20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Tweet This\" href=\"https:\/\/feeds.feedblitz.com\/_\/24\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/twitter20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Subscribe by email\" href=\"https:\/\/feeds.feedblitz.com\/_\/19\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/email20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Subscribe by RSS\" href=\"https:\/\/feeds.feedblitz.com\/_\/20\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/rss20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a rel=\"NOFOLLOW\" title=\"View Comments\" href=\"https:\/\/www.baeldung.com\/keytool-intro#respond\"><img decoding=\"async\" height=\"20\" style=\"border:0;margin:0;padding:0;\" src=\"https:\/\/assets.feedblitz.com\/i\/comments20.png\"><\/a>&#160;<a title=\"Follow Comments via RSS\" href=\"https:\/\/www.baeldung.com\/keytool-intro\/feed\/\"><img decoding=\"async\" height=\"20\" style=\"border:0;margin:0;padding:0;\" src=\"https:\/\/assets.feedblitz.com\/i\/commentsrss20.png\"><\/a>&#160;<\/div>\n\n<p class=\"syndicated-attribution\"><figure class= \\\"wp-block-image alignnone \\\"><img src= \\\"http:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-content\/uploads\/2016\/05\/logo2-2.png\\\" alt=\\\"IT\u96fb\u8166\u88dc\u7fd2 java\u88dc\u7fd2 \u70ba\u5927\u5bb6\u914d\u5c0d\u96fb\u8166\u88dc\u7fd2,IT freelance, \u79c1\u4eba\u8001\u5e2b, PHP\u88dc\u7fd2,CSS\u88dc\u7fd2,XML,Java\u88dc\u7fd2,MySQL\u88dc\u7fd2,graphic design\u88dc\u7fd2,\u4e2d\u5c0f\u5b78ICT\u88dc\u7fd2,\u4e00\u5c0d\u4e00\u79c1\u4eba\u88dc\u7fd2\u548cFreelance\u81ea\u7531\u5de5\u4f5c\u914d\u5c0d\u3002\\\"\/><figcaption>\u7acb\u523b\u8a3b\u518a\u53ca\u5831\u540d\u96fb\u8166\u88dc\u7fd2\u8ab2\u7a0b\u5427!<\/figcaption><\/figure>\r\n<\/br>Find A Teacher Form:\r\n<\/br>https:\/\/docs.google.com\/forms\/d\/1vREBnX5n262umf4wU5U2pyTwvk9O-JrAgblA-wH9GFQ\/viewform?edit_requested=true#responses\r\n<\/br><\/br>Email:\r\n<\/br>public1989two@gmail.com<br><br><br><br><br><br><br>\r\n<a href=www.itsec.hk style=color:#FFFFFF;>www.itsec.hk<\/a><br>\r\n<a href=\\\"www.itsec.vip\\\" style=color:#FFFFFF;>www.itsec.vip<\/a><br>\r\n<a href=\\\"www.itseceu.uk\\\" style=color:#FFFFFF;>www.itseceu.uk<\/a><br><\/p>","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Learn how to generate certificates with keytool.<\/p>\n<div><a title=\"Like on Facebook\" href=\"https:\/\/feeds.feedblitz.com\/_\/28\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/fblike20.png\"><\/a>&nbsp;<a title=\"Share on Google+\" href=\"https:\/\/feeds.feedblitz.com\/_\/30\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/googleplus20.png\"><\/a>&nbsp;<a title=\"Pin it!\" href=\"https:\/\/feeds.feedblitz.com\/_\/29\/634570196\/baeldung,\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/pinterest20.png\"><\/a>&nbsp;<a title=\"Tweet This\" href=\"https:\/\/feeds.feedblitz.com\/_\/24\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/twitter20.png\"><\/a>&nbsp;<a title=\"Subscribe by email\" href=\"https:\/\/feeds.feedblitz.com\/_\/19\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/email20.png\"><\/a>&nbsp;<a title=\"Subscribe by RSS\" href=\"https:\/\/feeds.feedblitz.com\/_\/20\/634570196\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/rss20.png\"><\/a>&nbsp;<a rel=\"NOFOLLOW\" title=\"View Comments\" href=\"https:\/\/www.baeldung.com\/keytool-intro#respond\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/comments20.png\"><\/a>&nbsp;<a title=\"Follow Comments via RSS\" href=\"https:\/\/www.baeldung.com\/keytool-intro\/feed\/\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/commentsrss20.png\"><\/a>&nbsp;<\/div>\n<\/div>","protected":false},"author":214,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Introduction to keytool - ITTeacherITFreelance.hk","description":"Learn how to generate certificates with keytool. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"},"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/62416"}],"collection":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/214"}],"replies":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=62416"}],"version-history":[{"count":8,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/62416\/revisions"}],"predecessor-version":[{"id":65866,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/62416\/revisions\/65866"}],"wp:attachment":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=62416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=62416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=62416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}