org.glite.slcs.pki
Class CertificateKeys

java.lang.Object
  extended by org.glite.slcs.pki.CertificateKeys

public class CertificateKeys
extends java.lang.Object

CertificateKeys is a wrapper class for a KeyPair. Adds functionalities to store the PrivateKey encrypted in PEM format.

Version:
$Revision: 1.4 $
Author:
Valery Tschopp

Constructor Summary
CertificateKeys()
          Constructor.
CertificateKeys(char[] password)
          Constructor.
CertificateKeys(int keySize)
          Contructor.
CertificateKeys(int keySize, char[] password)
          Creates a new key pair (private and public) for the given key size.
 
Method Summary
 char[] getPassword()
           
 java.lang.String getPEMPrivate()
          Gets the private key PEM encoded.
 java.security.PrivateKey getPrivate()
           
 java.security.PublicKey getPublic()
           
 void setPassword(char[] password)
          Sets the private key encryption password.
 void setPassword(java.lang.String password)
          Sets the private key encryption password.
 void storePEMPrivate(java.io.File file)
          Stores the private key in PEM format in the given file.
 void storePEMPrivate(java.lang.String filename)
          Stores the private key in PEM format in the given filename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CertificateKeys

public CertificateKeys(int keySize,
                       char[] password)
                throws java.security.GeneralSecurityException
Creates a new key pair (private and public) for the given key size. The password is used to store the private key crypted.

Parameters:
keySize - The keys size.
password - The password to store the private key crypted.
Throws:
java.security.GeneralSecurityException - If an error occurs.

CertificateKeys

public CertificateKeys(char[] password)
                throws java.security.GeneralSecurityException
Constructor. Encrypted private key and public key with default private key length of 1024.

Parameters:
password - The encryption password.
Throws:
java.security.GeneralSecurityException

CertificateKeys

public CertificateKeys(int keySize)
                throws java.security.GeneralSecurityException
Contructor. Unencrypted private and public key with a given key size.

Parameters:
keySize - 512, 1024 or 2048, The key length.
Throws:
java.security.GeneralSecurityException

CertificateKeys

public CertificateKeys()
                throws java.security.GeneralSecurityException
Constructor. Default keySize is 1024.

Throws:
java.security.GeneralSecurityException
Method Detail

getPrivate

public java.security.PrivateKey getPrivate()
Returns:
The private key or null if the key pair doesn't exist

getPublic

public java.security.PublicKey getPublic()
Returns:
The public key or null if the key pair doesn't exist

setPassword

public void setPassword(java.lang.String password)
Sets the private key encryption password.

Parameters:
password - The private key password.

setPassword

public void setPassword(char[] password)
Sets the private key encryption password.

Parameters:
password - The private key password.

storePEMPrivate

public void storePEMPrivate(java.lang.String filename)
                     throws java.io.IOException
Stores the private key in PEM format in the given filename. If the password is set the private key is store encrypted.

Parameters:
filename - The filename of the PEM file.
Throws:
java.io.IOException - If an IO error occurs.

storePEMPrivate

public void storePEMPrivate(java.io.File file)
                     throws java.io.IOException
Stores the private key in PEM format in the given file. If the password is set the private key is store encrypted.

Parameters:
file - The PEM file.
Throws:
java.io.IOException - If an IO error occurs.

getPEMPrivate

public java.lang.String getPEMPrivate()
                               throws java.io.IOException
Gets the private key PEM encoded. If the password is set, the PEM block is crypted.

Returns:
The PEM encoded private key.
Throws:
java.io.IOException

getPassword

public char[] getPassword()
Returns:
The private key password.