tribble.security
Class GenKeyPair

java.lang.Object
  extended bytribble.security.GenKeyPair

public class GenKeyPair
extends java.lang.Object

Public/private key pair generator. Generates a public/private key pair to be used for asymmetric (public key) encryption.

The public and private keys are written to text files formatted as XML. These key files can then be read by class KeyReader.

Since:
2003-03-13
Version:
$Revision: 1.6 $ $Date: 2003/08/09 17:24:32 $
Author:
David R. Tribble (david@tribble.com).
Copyright ©2003 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.
See Also:
KeyReader

Field Summary
static java.lang.String DFL_ALGORITHM
          Default key pair generation algorithm ("RSA").
static int DFL_KEYSIZE
          Default key pair bit size (1024).
 
Constructor Summary
GenKeyPair()
          Default constructor.
GenKeyPair(java.lang.String algo, int size)
          Constructor.
 
Method Summary
 java.security.KeyPair generate()
          Generate a public/private key pair.
static void main(java.lang.String[] args)
          Generate a public/private encryption key pair.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DFL_ALGORITHM

public static final java.lang.String DFL_ALGORITHM
Default key pair generation algorithm ("RSA").

See Also:
Constant Field Values

DFL_KEYSIZE

public static final int DFL_KEYSIZE
Default key pair bit size (1024).

See Also:
Constant Field Values
Constructor Detail

GenKeyPair

public GenKeyPair()
           throws java.security.GeneralSecurityException
Default constructor.

Throws:
java.security.NoSuchAlgorithmException - Thrown if the default generator algorithm is not available.
java.security.GeneralSecurityException
Since:
1.1, 2003-03-13

GenKeyPair

public GenKeyPair(java.lang.String algo,
                  int size)
           throws java.security.GeneralSecurityException
Constructor.

Parameters:
algo - Name of the public/private key pair generation algorithm to use, e.g., "DSA".
size - Key size (in bits), e.g., 1024.
Throws:
java.security.NoSuchAlgorithmException - Thrown if the specified generator algorithm is not available.
java.security.GeneralSecurityException
Since:
1.1, 2003-03-13
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        java.security.GeneralSecurityException
Generate a public/private encryption key pair.

Usage java tribble.security.GenKeyPair [-option...] public.xml private.xml

Options:

-a alg
Algorithm name (the default is RSA).

-s num
Key size (the default is 1024).

Writes the public half of the generated key pair to file public.xml, and the private half to file private.xml. The output files are in stand-alone XML format.

Throws:
java.security.GeneralSecurityException - Thrown if a security exception occurs.
java.io.IOException - Thrown if and I/O (write) error occurs.
Since:
1.1, 2003-03-13

generate

public java.security.KeyPair generate()
Generate a public/private key pair.

Returns:
A public/private key pair. Note that the private key of the pair must be kept secret by the user of the key pair.
Since:
1.1, 2003-03-13