Java GetKeyData Utility

Have you ever needed to extract a private key from a Java KeyStore? It's a pain, but Keytool only allows you to export the certificates, and not the RSA private keys. A colleague needed to do exactly that on Friday afernoon, so on Monday morning I wrote a little utility to do it.
 
The GetKeyData utility can be used to print both the certificate and private key of any PKI or SSL certificates you may have in a java keystore (as used by tomcat and other J2EE servers).
 
To use, simply download the class file and while in the same directory run:
 
java GetKeyData  <Keystore> <Key alias> <password> [<keypass>]
 
Where KeyStore is the filename of your keystore, and alias is the keys alias within the store. You also need to provide the password for the keystore, and optionally the password for the key itself, if it has one.
 
The utility will then print the public key / certificate and the private key to the console (stdout).
 
Instant private key liberation!
 
You may download the compiled java class here -> GetKeyData.class
And the source if you want to compile it yourself here -> GetKeyData.java
 
Enjoy ;-)
 
 
Tags: