I just created a self-signed certificate on a linux box running tomcat 6.
I created the keys like this, valid for 10 years:
keytool -genkey -alias tomcatorange -keyalg RSA -validity 3650
and copied the keystore into a folder in tomcat, and updated server.xml to point at the keystore.
Now my network admin is asking for the both the public and private key ( for our load balancer)
I can generate the public key using:
openssl s_client -connect mydomain.com:8443
But how can I export/retrieve the private key?
On Windows servers, the OS manages your certificate files for you in a hidden folder, but you can retrieve the private key by exporting a “. pfx” file that contains the certificate(s) and private key. Open Microsoft Management Console (MMC). In the Console Root expand Certificates (Local Computer).
Go to: Certificates > Personal > Certificates. Right-click on the certificate you wish to export and go to All Tasks and hit Export. Hit Next on the Certificate Export Wizard to begin the process. Select “Yes, export the private key” and hit next.
It is a little tricky. First you can use keytool to put the private key into PKCS12 format, which is more portable/compatible than Java's various keystore formats. Here is an example taking a private key with alias 'mykey' in a Java keystore and copying it into a PKCS12 file named myp12file.p12
. [note that on most screens this command extends beyond the right side of the box: you need to scroll right to see it all]
keytool -v -importkeystore -srckeystore .keystore -srcalias mykey -destkeystore myp12file.p12 -deststoretype PKCS12 Enter destination keystore password: Re-enter new password: Enter source keystore password: [Storing myp12file.p12]
Now the file myp12file.p12
contains the private key in PKCS12 format which may be used directly by many software packages or further processed using the openssl pkcs12
command. For example,
openssl pkcs12 -in myp12file.p12 -nocerts -nodes Enter Import Password: MAC verified OK Bag Attributes friendlyName: mykey localKeyID: 54 69 6D 65 20 31 32 37 31 32 37 38 35 37 36 32 35 37 Key Attributes: <No Attributes> -----BEGIN RSA PRIVATE KEY----- MIIC... . . . -----END RSA PRIVATE KEY-----
Prints out the private key unencrypted.
Note that this is a private key, and you are responsible for appreciating the security implications of removing it from your Java keystore and moving it around.
Use Keystore Explorer gui - http://keystore-explorer.sourceforge.net/ - allows you to extract the private key from a .jks in various formats.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With