cc.security
Class KeyStoreUtil

java.lang.Object
  extended by cc.security.KeyStoreUtil

public class KeyStoreUtil
extends java.lang.Object

Simple utility for managing common KeyStore tasks.


Field Summary
private static java.lang.String endLine
           
 
Constructor Summary
KeyStoreUtil()
           
 
Method Summary
static void appendHexValue(java.lang.StringBuffer buffer, byte b)
          Helper method that converts a single byte to a hex string representation.
static void appendHexValue(java.lang.StringBuffer buffer, byte[] bytes)
          Helper that appends a hex representation of a byte array to an existing StringBuffer.
static java.util.List getAliases(java.security.KeyStore keystore)
          List all the key and certificate aliases in the keystore.
static java.security.cert.Certificate getCertificate(java.security.KeyStore keystore, java.lang.String alias)
          Get a certificate from the keystore by name.
static java.security.Key getKey(java.security.KeyStore keystore, java.lang.String alias, java.lang.String password)
          Get a private key from the keystore by name and password.
static java.security.KeyStore getKeyStore(java.io.InputStream in, java.lang.String password)
          Get a KeyStore object given the keystore filename and password.
static java.security.KeyStore getKeyStore(java.lang.String filename, java.lang.String password)
          Get a KeyStore object given the keystore filename and password.
static java.lang.String getUserInput(java.lang.String prompt)
          Helper method to solicit a line of user input from the console.
static void main(java.lang.String[] args)
          As an application, this class will operate something like the keytool -list command: it will read out every alias in the keystore, and with the user's provided password for a given key will write out all data on the key and/or certificate.
static java.lang.String spillBeans(java.security.cert.Certificate cert)
          Dump all data about the certificate to the console.
static java.lang.String spillBeans(java.security.Key key)
          Dump all data about the private key to the console.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

endLine

private static final java.lang.String endLine
Constructor Detail

KeyStoreUtil

public KeyStoreUtil()
Method Detail

getKeyStore

public static java.security.KeyStore getKeyStore(java.lang.String filename,
                                                 java.lang.String password)
                                          throws java.security.KeyStoreException
Get a KeyStore object given the keystore filename and password.

Throws:
java.security.KeyStoreException

getKeyStore

public static java.security.KeyStore getKeyStore(java.io.InputStream in,
                                                 java.lang.String password)
                                          throws java.security.KeyStoreException
Get a KeyStore object given the keystore filename and password.

Throws:
java.security.KeyStoreException

getAliases

public static java.util.List getAliases(java.security.KeyStore keystore)
                                 throws java.security.KeyStoreException
List all the key and certificate aliases in the keystore.

Returns:
A list of Strings
Throws:
java.security.KeyStoreException

getKey

public static java.security.Key getKey(java.security.KeyStore keystore,
                                       java.lang.String alias,
                                       java.lang.String password)
                                throws java.security.GeneralSecurityException
Get a private key from the keystore by name and password.

Throws:
java.security.GeneralSecurityException

getCertificate

public static java.security.cert.Certificate getCertificate(java.security.KeyStore keystore,
                                                            java.lang.String alias)
                                                     throws java.security.GeneralSecurityException
Get a certificate from the keystore by name.

Throws:
java.security.GeneralSecurityException

spillBeans

public static java.lang.String spillBeans(java.security.Key key)
Dump all data about the private key to the console.


spillBeans

public static java.lang.String spillBeans(java.security.cert.Certificate cert)
                                   throws java.security.GeneralSecurityException
Dump all data about the certificate to the console.

Throws:
java.security.GeneralSecurityException

getUserInput

public static java.lang.String getUserInput(java.lang.String prompt)
                                     throws java.io.IOException
Helper method to solicit a line of user input from the console.

Throws:
java.io.IOException

appendHexValue

public static void appendHexValue(java.lang.StringBuffer buffer,
                                  byte b)
Helper method that converts a single byte to a hex string representation.

Parameters:
b - byte Byte to convert

appendHexValue

public static void appendHexValue(java.lang.StringBuffer buffer,
                                  byte[] bytes)
Helper that appends a hex representation of a byte array to an existing StringBuffer.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
As an application, this class will operate something like the keytool -list command: it will read out every alias in the keystore, and with the user's provided password for a given key will write out all data on the key and/or certificate.

Throws:
java.lang.Exception