{"id":356,"date":"2007-10-21T00:00:00","date_gmt":"2007-10-21T00:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=356"},"modified":"2007-10-21T00:00:00","modified_gmt":"2007-10-21T00:00:00","slug":"Signing JAR Files","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=356","title":{"rendered":"Signing JAR Files"},"content":{"rendered":"<p><DIV><br \/>\n<DIV id=PageTitle>Signing JAR Files<\/DIV><br \/>\n<BLOCKQUOTE>You use the JAR Signing and Verification Tool to sign JAR files. You invoke the JAR Signing and Verification Tool by using the <TT>jarsigner<\/TT> command, so we&#8217;ll refer to it as &#8220;Jarsigner&#8221; for short.<br \/>\n<P>To sign a JAR file, you must first have a private key. Private keys and their associated public-key certificates are stored in password-protected databases called <EM>keystores<\/EM>. A keystore can hold the keys of many potential signers. Each key in the keystore can be identified by an <EM>alias<\/EM> which is typically the name of the signer who owns the key. The key belonging to Rita Jones might have the alias &#8220;rita&#8221;, for example. <\/P><br \/>\n<P>The basic form of the command for signing a JAR file is <\/P><br \/>\n<BLOCKQUOTE><PRE>jarsigner <I>jar-file alias<\/I><br \/>\n<\/PRE><\/BLOCKQUOTE>In this command:<br \/>\n<UL><br \/>\n<LI><TT>jar-file<\/TT> is the pathname of the JAR file that&#8217;s to be signed. <\/LI><br \/>\n<LI><TT>alias<\/TT> is the alias identifying the private key that&#8217;s to be used to sign the JAR file, and the key&#8217;s associated certificate. <\/LI><\/UL><br \/>\n<P>The Jarsigner tool will prompt you for the passwords for the keystore and alias. <\/P><br \/>\n<P>This basic form of the command assumes that the keystore to be used is in a file named <TT>.keystore<\/TT> in your home directory. It will create signature and signature block files with names <TT>x.SF<\/TT> and <TT>x.DSA<\/TT> respectively, where <TT>x<\/TT> is the first eight letters of the alias, all converted to upper case. This basic command will <EM>overwrite<\/EM> the original JAR file with the signed JAR file. <\/P><br \/>\n<P>In practice, you may want to use this command in conjunction with one or more of these options, which must precede the <TT>jar-file<\/TT> pathname: <BR><BR><br \/>\n<TABLE cellSpacing=3 border=1><br \/>\n<CAPTION><STRONG>Jarsigner Command Options <\/STRONG><\/CAPTION><br \/>\n<TBODY><br \/>\n<TR><br \/>\n<TH>Option<\/TH><br \/>\n<TH>Description<\/TH><\/TR><br \/>\n<TR><br \/>\n<TD><TT>-keystore<\/TT>&nbsp;<I>url<\/I><\/TD><br \/>\n<TD>Specifies a keystore to be used if you don&#8217;t want to use the <TT>.keystore<\/TT> default database.<\/TD><\/TR><br \/>\n<TR><br \/>\n<TD><TT>-storepass<\/TT>&nbsp;<I>password<\/I><\/TD><br \/>\n<TD>Allows you to enter the keystore&#8217;s password on the command line rather than be prompted for it. <\/TD><\/TR><br \/>\n<TR><br \/>\n<TD><TT>-keypass<\/TT>&nbsp;<I>password<\/I><\/TD><br \/>\n<TD>Allows you to enter your alias&#8217;s password on the command line rather than be prompted for it.<\/TD><\/TR><br \/>\n<TR><br \/>\n<TD><TT>-sigfile<\/TT>&nbsp;<I>file<\/I><\/TD><br \/>\n<TD>Specifies the base name for the .SF and .DSA files if you don&#8217;t want the base name to be taken from your alias. <I>file<\/I> must be composed only of upper case letters (A-Z), numerals (0-9), hyphen (-), and underscore (_).<\/TD><\/TR><br \/>\n<TR><br \/>\n<TD><TT>-signedjar<\/TT>&nbsp;<I>file<\/I><\/TD><br \/>\n<TD>Specifies the name of the signed JAR file to be generated if you don&#8217;t want the original unsigned file to be overwritten with the signed file.<\/TD><\/TR><\/TBODY><\/TABLE><\/P><\/BLOCKQUOTE><br \/>\n<H3>Example<\/H3><br \/>\n<BLOCKQUOTE>Let&#8217;s look at a couple of examples of signing a JAR file with the Jarsigner tool. In these examples we will assume:<br \/>\n<UL><br \/>\n<LI>your alias is &#8220;johndoe&#8221;. <\/LI><br \/>\n<LI>the keystore you want to use is in a file named &#8220;mykeys&#8221; in the current working directory. <\/LI><br \/>\n<LI>the keystore&#8217;s password is &#8220;abc123&#8221;. <\/LI><br \/>\n<LI>the password for your alias is &#8220;mypass&#8221;. <\/LI><\/UL>Under these assumptions, you could use this command to sign a JAR file named <TT>app.jar<\/TT>:<br \/>\n<BLOCKQUOTE><PRE>jarsigner -keystore mykeys -storepass abc123<br \/>\n          -keypass mypass app.jar johndoe<br \/>\n<\/PRE><\/BLOCKQUOTE><br \/>\n<P>Because this command doesn&#8217;t make use of the <TT>-sigfile<\/TT> option, the .SF and .DSA files it creates would be named <TT>JOHNDOE.SF<\/TT> and <TT>JOHNDOE.DSA<\/TT>. Because the command doesn&#8217;t use the <TT>-signedjar<\/TT> option, the resulting signed file will overwrite the original version of <TT>app.jar<\/TT>. <\/P><br \/>\n<P>Let&#8217;s look at what would happen if you used a different combination of options: <\/P><br \/>\n<BLOCKQUOTE><PRE>jarsigner -keystore mykeys -sigfile SIG<br \/>\n          -signedjar SignedApp.jar app.jar johndoe<br \/>\n<\/PRE><\/BLOCKQUOTE><br \/>\n<P>This time, you would be prompted to enter the passwords for both the keystore and your alias because the passwords aren&#8217;t specified on the command line. The signature and signature block files would be named <TT>SIG.SF<\/TT> and <TT>SIG.DSA<\/TT>, respectively, and the signed JAR file <TT>SignedApp.jar<\/TT> would be placed in the current directory. The original unsigned JAR file would remain unchanged. <\/P><\/BLOCKQUOTE><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Signing JAR Files You use the JAR Signing and Verification Tool to sign JAR files. You invoke the JAR Signing and Verification Tool by using the jarsigner command, so we&#8217;ll refer to it as &#8220;Jarsigner&#8221; for short. To sign a JAR file, you must first have a private key. Private keys and their associated public-key &hellip; <a href=\"https:\/\/www.strongd.net\/?p=356\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Signing JAR Files<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":0,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}