net.sourceforge.jcetaglib.tools
Class KeyTools

java.lang.Object
  extended bynet.sourceforge.jcetaglib.tools.KeyTools

public class KeyTools
extends java.lang.Object

Tools to handle common key and keystore operations.

Version:
$Id: KeyTools.java,v 1.4 2004/04/15 07:28:36 hamgert Exp $

Method Summary
static java.security.KeyStore createP12(java.lang.String alias, java.security.PrivateKey privKey, java.security.cert.X509Certificate cert, java.security.cert.Certificate[] cachain)
          Creates PKCS12-file that can be imported in IE or Netscape.
static java.security.KeyStore createP12(java.lang.String alias, java.security.PrivateKey privKey, java.security.cert.X509Certificate cert, java.security.cert.X509Certificate cacert)
          Creates PKCS12-file that can be imported in IE or Netscape.
static java.security.PrivateKey decryptPrivateKey(byte[] wrappedKey, java.lang.String password)
          decrypts an RSA private key.
static java.security.cert.Certificate[] getCertChain(java.security.KeyStore keyStore, java.lang.String privateKeyAlias)
          Retrieves the certificate chain from a keystore.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createP12

public static java.security.KeyStore createP12(java.lang.String alias,
                                               java.security.PrivateKey privKey,
                                               java.security.cert.X509Certificate cert,
                                               java.security.cert.X509Certificate cacert)
                                        throws java.lang.Exception
Creates PKCS12-file that can be imported in IE or Netscape. The alias for the private key is set to 'privateKey' and the private key password is null.

Parameters:
alias - the alias used for the key entry
privKey - RSA private key
cert - user certificate
cacert - CA-certificate or null if only one cert in chain, in that case use 'cert'.
Returns:
byte[] containing PKCS12-file in binary format
Throws:
java.lang.Exception - if input parameters are not OK or certificate generation fails

createP12

public static java.security.KeyStore createP12(java.lang.String alias,
                                               java.security.PrivateKey privKey,
                                               java.security.cert.X509Certificate cert,
                                               java.security.cert.Certificate[] cachain)
                                        throws java.lang.Exception
Creates PKCS12-file that can be imported in IE or Netscape. The alias for the private key is set to 'privateKey' and the private key password is null.

Parameters:
alias - the alias used for the key entry
privKey - RSA private key
cert - user certificate
cachain - CA-certificate chain or null if only one cert in chain, in that case use 'cert'.
Returns:
byte[] containing PKCS12-file in binary format
Throws:
java.lang.Exception - if input parameters are not OK or certificate generation fails

getCertChain

public static java.security.cert.Certificate[] getCertChain(java.security.KeyStore keyStore,
                                                            java.lang.String privateKeyAlias)
                                                     throws java.security.KeyStoreException
Retrieves the certificate chain from a keystore.

Parameters:
keyStore - the keystore, which has been loaded and opened.
privateKeyAlias - the alias of the privatekey for which the certchain belongs.
Returns:
array of Certificate, length of array is 0 if no certificates are found.
Throws:
java.security.KeyStoreException

decryptPrivateKey

public static java.security.PrivateKey decryptPrivateKey(byte[] wrappedKey,
                                                         java.lang.String password)
                                                  throws java.lang.Exception
decrypts an RSA private key.

Parameters:
wrappedKey - the key in bytes
password - password as string
Returns:
PrivateKey structure
Throws:
java.lang.Exception