com.caplin.keymaster.keygenerator
Class KeyGenerator

java.lang.Object
  extended by com.caplin.keymaster.keygenerator.KeyGenerator

public class KeyGenerator
extends Object

KeyGenerator creates a set of keys, one private, one public and another version of the public key in DER (binary) format. The DER key is used by Caplin Liberator to authenticate the user. The private key is used by StandardKeyMaster to generate a token for a request made by a user. This class uses the external library bcprov-jdk14-125.jar to provide some security functionality.

This is one of the entry point classes for the package. The class expects two arguments.

  1. The name of a properties file that has the attributes listed in the example file below.
  2. The name of a security provider. It can technically be anything, but it must match the name of the security provider listed in the configuration file for the servlet being used i.e. web.xml. The attribute in that file is "encrypting.generator.security.provider.name".

Property Example Description
key.generator.private.key.store.filename 'privatekey.store' The name of the file that the private key will be stored in.
key.generator.public.key.store.filename 'publickey.store' The name of the file that the public key will be stored in.
key.generator.public.key.der.filename 'publickey.der' The name of the DER formatted public key. The file should end in '.der'.
key.generator.key.size '1024' The size of the generated key. Both keys use this size.
key.generator.security.provider.class.name 'org.bouncycastle.jce.provider.BouncyCastleProvider' The name of the encryption package. Need to have a JAR or similar to match the package.
key.generator.security.provider.name 'BC' The name of the security provider that the key will be produced with.
key.generator.Level 'FINEST' Specifies the level of logging required. @see java.util.logging.Level
key.generator.FilenameAttribute 'log.txt' Specifies the name of the file to log messages to. The file is NOT appended.
File is created relative to the users current location, unless a path is specified as well (e.g. ../log.txt).

Author:
David Shorten

Constructor Summary
KeyGenerator(String propsFilename, String serverName)
           This constructor initialises the class variables to the properties specified in the properties file.
 
Method Summary
 KeyPair generate()
          Generates a pair of keys using the KeyPairGenerator method generateKeyPair.
static void main(String[] args)
          Creates an instance of the KeyGenerator class and generates the three keys.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyGenerator

public KeyGenerator(String propsFilename,
                    String serverName)
             throws IOException,
                    ClassNotFoundException,
                    IllegalAccessException,
                    InstantiationException,
                    NoSuchAlgorithmException,
                    NoSuchProviderException

This constructor initialises the class variables to the properties specified in the properties file.

Parameters:
propsFilename - String containing the location of the properties file.
serverName - String specifying the name of the server to create the keys for.
Throws:
IOException - Thrown by FileInputStream
ClassNotFoundException - thrown by internal method
IllegalAccessException - thrown by internal method
InstantiationException - thrown by internal method
NoSuchAlgorithmException - thrown by internal method
NoSuchProviderException - thrown by internal method
Method Detail

generate

public KeyPair generate()

Generates a pair of keys using the KeyPairGenerator method generateKeyPair.

Returns:
KeyPair that has been created by a KeyPairGenerator
See Also:
KeyPairGenerator

main

public static void main(String[] args)
                 throws IOException,
                        ClassNotFoundException,
                        IllegalAccessException,
                        InstantiationException,
                        NoSuchAlgorithmException,
                        NoSuchProviderException

Creates an instance of the KeyGenerator class and generates the three keys.

Parameters:
args - Two expected. The name of the properties file and the server name.
Throws:
IOException - thrown by KeyGenerator constructor
ClassNotFoundException - thrown by KeyGenerator constructor
IllegalAccessException - thrown by KeyGenerator constructor
InstantiationException - thrown by KeyGenerator constructor
NoSuchAlgorithmException - thrown by KeyGenerator constructor
NoSuchProviderException - thrown by KeyGenerator constructor


Please send bug reports and comments to Caplin support