<rdf:RDF
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xml:base='http://bliki.rimuhosting.com/rdf'>
    <s:Snip rdf:about='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/keytool'
         s:cUser='alex'
         s:oUser=''
         s:mUser='alex'>
        <s:name>knowledgebase/linux/miscapplications/keytool</s:name>
        <s:content>Here&apos;s how you can use SSL certs with Java apps and vice versa.&#xD;&#xA;&#xD;&#xA;Generally, we use OpenSSL to generate a private key, then generate CSRs: http://rimuhosting.com/howto/modssl.jsp&#xD;&#xA;&#xD;&#xA;For Java apps, the private key has to be stored in a &quot;keystore&quot; which needs to be created with the keytool command: http://tomcat.apache.org/tomcat-5.5-doc/ssl-howto.html&#xD;&#xA;&#xD;&#xA;Importing the private key into the keystore is non-trivial, as far as I know, as is exporting a private key from a keystore.  So I suggest the following procedure: generate the private key with keytool, then export it so it can also be used with Apache (and the same SSL cert).  Here&apos;s the procedure I got to work with this:&#xD;&#xA;{code}as root: $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA{code} This will create /root/.keystore  Write down the password you used.&#xD;&#xA;{code:java}&#xD;&#xA;#call this file DumpPrivateKey.java&#xD;&#xA;import java.io.FileInputStream;&#xD;&#xA;import java.security.KeyStore;&#xD;&#xA;import java.security.Key;&#xD;&#xA; &#xD;&#xA;public class DumpPrivateKey {&#xD;&#xA;        static public void main(String[] args) {&#xD;&#xA;                try {&#xD;&#xA;                        KeyStore ks = KeyStore.getInstance(&quot;jks&quot;);&#xD;&#xA;                        ks.load(new FileInputStream(&quot;/root/.keystore&quot;),&#xD;&#xA;                                 &quot;password&quot;.toCharArray());&#xD;&#xA;                        Key key = ks.getKey(&quot;tomcat&quot;,&#xD;&#xA;                                 &quot;password&quot;.toCharArray());&#xD;&#xA;                        System.out.write(key.getEncoded());&#xD;&#xA;                } catch (Exception e) {&#xD;&#xA;                        e.printStackTrace();&#xD;&#xA;                }&#xD;&#xA;        }&#xD;&#xA;}&#xD;&#xA;{code}&#xD;&#xA;Change the password in that file appropriately. &#xD;&#xA;{code}javac DumpPrivateKey.java{code}&#xD;&#xA;Then create this bash script:&#xD;&#xA;{code:sh}&#xD;&#xA;# cat dump_private_key.sh &#xD;&#xA;#!/bin/sh&#xD;&#xA;ALIAS=tomcat&#xD;&#xA;PKEY_8=privatekey.pkcs8&#xD;&#xA;PKEY_64=privatekey.b64&#xD;&#xA;CERT_64=certificate.b64&#xD;&#xA;CERT_12=certificate.p12&#xD;&#xA;keytool -alias ${ALIAS} -export -rfc &gt;${CERT_64}&#xD;&#xA;java -classpath . DumpPrivateKey &gt;${PKEY_8}&#xD;&#xA;(echo &quot;-----BEGIN PRIVATE KEY-----&quot; ;&#xD;&#xA; openssl enc -in ${PKEY_8} -a;&#xD;&#xA; echo &quot;-----END PRIVATE KEY-----&quot;) &gt;${PKEY_64}&#xD;&#xA;openssl pkcs12 -inkey ${PKEY_64} -in ${CERT_64} -out ${CERT_12} -export &#xD;&#xA;#rm ${PKEY_8} ${PKEY_64} ${CERT_64}&#xD;&#xA;echo ${CERT_12}&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Then privatekey.b64 will have the private key you want.&#xD;&#xA;&#xD;&#xA;Links:&#xD;&#xA;http://forum.java.sun.com/thread.jspa?threadID=154587&amp;start=0&amp;tstart=0&#xD;&#xA;http://tjworld.net/software/codesigning/index.html&#xD;&#xA;http://www.theserverside.com/discussions/thread.tss?thread_id=22243&#xD;&#xA;http://i-proving.ca/space/Technologies/JBoss/Configuring+JBoss+SSL</s:content>
        <s:mTime>2008-06-26 23:51:08.0</s:mTime>
        <s:cTime>2008-06-26 23:51:08.0</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/webserver/drupal notes'/>
                <rdf:li rdf:resource='#snipsnap-search'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/ruby on rails'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/mass emailing best practices'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/rimuhosting ssh access'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/ajax autocomplete'/>
                <rdf:li rdf:resource='#alex'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/liferay install on tomcat 5.5'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/3rd party php5.2 packages for Centos'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/where has my disk space gone'/>
            </rdf:Bag>
        </s:snipLinks>
        <s:attachments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
    </s:Snip>
</rdf:RDF>
