anon.crypto
Class AsymmetricCryptoKeyPair

java.lang.Object
  extended by anon.crypto.AsymmetricCryptoKeyPair
Direct Known Subclasses:
DSAKeyPair, RSAKeyPair

public class AsymmetricCryptoKeyPair
extends java.lang.Object

A key pair used for signing and encryption with an asymmetric cryptographic algorithm.

Author:
Rolf Wendolsky

Field Summary
private static MyDSAPrivateKey dsaKey
           
static int KEY_LENGTH_1024
           
static int KEY_LENGTH_512
           
private  IMyPrivateKey m_privateKey
           
private  IMyPublicKey m_publicKey
           
private static java.util.Vector ms_privateKeyClasses
          Stores all registered private key classes.
private static java.util.Vector ms_publicKeyClasses
          Stores all registered public key classes.
private static MyRSAPrivateKey rsaKey
           
 
Constructor Summary
AsymmetricCryptoKeyPair(IMyPrivateKey a_privateKey)
          Creates a new key pair from a private key.
AsymmetricCryptoKeyPair(org.bouncycastle.asn1.pkcs.PrivateKeyInfo a_keyInfo)
          Creates a new key pair from a PrivateKeyInfo.
 
Method Summary
private static java.security.Key createAsymmetricCryptoKey(java.lang.Object a_keyInfo, java.util.Enumeration a_keyClasses)
           
static IMyPublicKey createPublicKey(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo a_keyInfo)
          Creates a new public key from a SubjectPublicKeyInfo.
 IMyPrivateKey getPrivate()
          Returns the private key.
private static java.util.Enumeration getPrivateKeyClasses()
          Returns all registered private key classes.
 IMyPublicKey getPublic()
          Returns the public key.
private static java.util.Enumeration getPublicKeyClasses()
          Returns all registered public key classes.
protected static boolean isValidKeyPair(AsymmetricCryptoKeyPair a_keyPair)
          Tests if a given key pair is a valid key pair.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_LENGTH_512

public static final int KEY_LENGTH_512
See Also:
Constant Field Values

KEY_LENGTH_1024

public static final int KEY_LENGTH_1024
See Also:
Constant Field Values

dsaKey

private static final MyDSAPrivateKey dsaKey

rsaKey

private static final MyRSAPrivateKey rsaKey

ms_privateKeyClasses

private static java.util.Vector ms_privateKeyClasses
Stores all registered private key classes.


ms_publicKeyClasses

private static java.util.Vector ms_publicKeyClasses
Stores all registered public key classes.


m_privateKey

private IMyPrivateKey m_privateKey

m_publicKey

private IMyPublicKey m_publicKey
Constructor Detail

AsymmetricCryptoKeyPair

public AsymmetricCryptoKeyPair(IMyPrivateKey a_privateKey)
Creates a new key pair from a private key.

Parameters:
a_privateKey - a private key

AsymmetricCryptoKeyPair

public AsymmetricCryptoKeyPair(org.bouncycastle.asn1.pkcs.PrivateKeyInfo a_keyInfo)
                        throws java.security.InvalidKeyException
Creates a new key pair from a PrivateKeyInfo. It does this by creating a new instance of all available private key classes with the PrivateKeyInfo as constructor argument. Therefore, all private key classes that should be able to be loaded dynamically must implement a constructor that has only one argument - a PrivateKeyInfo.

Parameters:
a_keyInfo - a PrivateKeyInfo object
Throws:
java.security.InvalidKeyException - if no private key could be created from this key info
See Also:
IMyPrivateKey, ClassUtil.loadClasses()
Method Detail

createPublicKey

public static final IMyPublicKey createPublicKey(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo a_keyInfo)
                                          throws java.security.InvalidKeyException
Creates a new public key from a SubjectPublicKeyInfo. It does this by creating a new instance of all available public key classes with the SubjectPublicKeyInfo as constructor argument. Therefore, all public key classes that should be able to be loaded dynamically must implement a constructor that has only one argument - a SubjectPublicKeyInfo.

Parameters:
a_keyInfo - a SubjectPublicKeyInfo describing a public key
Returns:
the corresponding public key to this key info
Throws:
java.security.InvalidKeyException - if no public key could be created from this key info
See Also:
ClassUtil.loadClasses(), IMyPublicKey

getPrivate

public final IMyPrivateKey getPrivate()
Returns the private key.

Returns:
the private key

getPublic

public final IMyPublicKey getPublic()
Returns the public key.

Returns:
the public key

isValidKeyPair

protected static final boolean isValidKeyPair(AsymmetricCryptoKeyPair a_keyPair)
Tests if a given key pair is a valid key pair. Key pair create or getInstance methods should not return a key pair the has not been tested with this method!

Parameters:
a_keyPair - an AsymmetricKeyPair
Returns:
true if the key pair is valid; false otherwise

createAsymmetricCryptoKey

private static java.security.Key createAsymmetricCryptoKey(java.lang.Object a_keyInfo,
                                                           java.util.Enumeration a_keyClasses)
                                                    throws java.security.InvalidKeyException
Throws:
java.security.InvalidKeyException

getPrivateKeyClasses

private static java.util.Enumeration getPrivateKeyClasses()
Returns all registered private key classes.

Returns:
all registered private key classes
See Also:
ClassUtil.loadClasses(), IMyPrivateKey

getPublicKeyClasses

private static java.util.Enumeration getPublicKeyClasses()
Returns all registered public key classes.

Returns:
all registered public key classes
See Also:
ClassUtil.loadClasses(), IMyPublicKey