{"id":1146,"date":"2009-09-16T22:16:52","date_gmt":"2009-09-17T03:16:52","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=1146"},"modified":"2020-01-28T15:39:56","modified_gmt":"2020-01-28T20:39:56","slug":"java-key-store-jks","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=1146","title":{"rendered":"Java Key Store (jks)"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#Key_Store\">Key Store<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Generate_Private_Key\">Generate Private Key<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Inspect_keys\">Inspect keys<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Generate_CSR\">Generate CSR<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Import_Signed_Cert\">Import Signed Cert<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Delete_a_Key\">Delete a Key<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Transfer_Private_Key_from_One_Keystore_to_Another\">Transfer Private Key from One Keystore to Another<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Print_cert_used_by_a_remote_site\">Print cert used by a remote site<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"Key_Store\"><h2>Key Store<\/h2><\/span>\n<span id=\"Generate_Private_Key\"><h3>Generate Private Key<\/h3><\/span>\n<p>* Generate a self-signed keypair with:<br \/>\n&#8211; alias: myhost<br \/>\n&#8211; CN: CN=myhost.mytest.local, OU=Lab, O=My Test, L=Reston, S=Virginia, C=US<br \/>\n&#8211; key algorithm: RSA<br \/>\n&#8211; key size: 2048<br \/>\n&#8211; signature algorithm: SHA1withRSA<br \/>\n&#8211; valid for: 360 days<br \/>\n&#8211; protected by password: secret<br \/>\n* Stored in a Java key store file:<br \/>\n&#8211; named: myhost.jks<br \/>\n&#8211; with password: secret<\/p>\n<pre lang=\"batch\">keytool -genkey -alias myhost -keyalg RSA -sigalg SHA1withRSA -keysize 2048 -keystore myhost.jks -storepass secret -keypass secret -dname \"CN=myhost.mytest.local, OU=Lab, O=My Test, L=Reston, S=Virginia, C=US\" -validity 360\n<\/pre>\n<span id=\"Inspect_keys\"><h3>Inspect keys<\/h3><\/span>\n<p>* Print out details about key with alias <em>myhost<\/em><\/p>\n<pre lang=\"batch\">keytool -list -v -alias myhost -keystore myhost.jks\n<\/pre>\n<span id=\"Generate_CSR\"><h3>Generate CSR<\/h3><\/span>\n<pre lang=\"batch\">keytool -certreq -alias myhost -sigalg SHA1withRSA -file myhost.csr -keystore myhost.jks\n<\/pre>\n<span id=\"Import_Signed_Cert\"><h3>Import Signed Cert<\/h3><\/span>\n<p>* Need to append <em>ca_root.cer<\/em> to <em>signed.cer<\/em> so that both can be imported at once.<\/p>\n<pre lang=\"batch\">keytool -import -v -keystore myhost.jks -alias myhost -storepass secret -file signed.cer\n<\/pre>\n<span id=\"Delete_a_Key\"><h3>Delete a Key<\/h3><\/span>\n<pre lang=\"batch\">keytool -delete -alias myhost -keystore myhost.jks -storepass secret \n<\/pre>\n<span id=\"Transfer_Private_Key_from_One_Keystore_to_Another\"><h3>Transfer Private Key from One Keystore to Another<\/h3><\/span>\n<pre lang=\"bash\">keytool -importkeystore -srckeystore srckeystore.jks -srcstorepass changeit -srckeypass changeit -destkeystore destkeystore.jks -deststorepass changeit -destkeypass changeit -alias test\n\n<\/pre>\n<span id=\"Print_cert_used_by_a_remote_site\"><h3>Print cert used by a remote site<\/h3><\/span>\n<pre lang=\"batch\">keytool -printcert -sslserver $host[:$port]\nkeytool -printcert -sslserver www.google.com:443\n\n# Output RFC format (cert files)\nkeytool -printcert -rfc -sslserver www.google.com:443<\/pre>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/technotes\/tools\/windows\/keytool.html\">Java 7 keytool &#8211; Key and Certificate Management Tool<\/a><br \/>\n* <a href=\"http:\/\/www.sslshopper.com\/article-most-common-java-keytool-keystore-commands.html\">The Most Common Java Keytool Keystore Commands<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Key Store Generate Private Key * Generate a self-signed keypair with: &#8211; alias: myhost &#8211; CN: CN=myhost.mytest.local, OU=Lab, O=My Test, L=Reston, S=Virginia, C=US &#8211; key algorithm: RSA &#8211; key size: 2048 &#8211; signature algorithm: SHA1withRSA &#8211; valid for: 360 days &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=1146\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14,55],"tags":[155],"class_list":["post-1146","post","type-post","status-publish","format-standard","hentry","category-java","category-ssl","tag-keystore"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-iu","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1146"}],"version-history":[{"count":5,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1146\/revisions"}],"predecessor-version":[{"id":12392,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1146\/revisions\/12392"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}