au.net.aba.crypto.provider
Class RSAKeyFactory

java.lang.Object
  |
  +--java.security.KeyFactorySpi
        |
        +--au.net.aba.crypto.provider.RSAKeyFactory

public class RSAKeyFactory
extends java.security.KeyFactorySpi

This class is used to convert RSA keys into a format usable by the ABA provider. Currently this class can convert from a KeySpec into a Key, or from one of the standard RSA Key interfaces into an ABA key.

The supported KeySpec classes are AsciiEncodedKeySpec, RSAPrivateCrtKeySpec, RSAPublicKeySpec, X509EncodedKeySpec and PKCS8EncodedKeySpec.

The supported RSA Key interfaces are RSAPublicKey, RSAPrivateKey and RSAPrivateCrtKey.

This class should not be instantiated directly, instead use the java.security.KeyFactory interface.

See Also:
java.security.KeyFactory, , , , , , ,

Field Summary
static java.lang.String ident
           
 
Constructor Summary
RSAKeyFactory()
           
 
Method Summary
protected  java.security.PrivateKey engineGeneratePrivate(java.security.spec.KeySpec keySpec)
          Generates a private key object from the provided key specification (key material).
protected  java.security.PublicKey engineGeneratePublic(java.security.spec.KeySpec keySpec)
          Generates a public key object from the provided key specification (key material).
protected  java.security.spec.KeySpec engineGetKeySpec(java.security.Key key, java.lang.Class spec)
          Returns a specification (key material) of the given key object.
protected  java.security.Key engineTranslateKey(java.security.Key key)
          Translates a key object, whose provider may be unknown or potentially untrusted, into a corresponding key object of this key factory.
protected static java.math.BigInteger[] parseKey(byte[] keyBytes)
          Parse a key from the ABA/PGP format into an array of BigIntegers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ident

public static final java.lang.String ident
Constructor Detail

RSAKeyFactory

public RSAKeyFactory()
Method Detail

engineGeneratePrivate

protected java.security.PrivateKey engineGeneratePrivate(java.security.spec.KeySpec keySpec)
                                                  throws java.security.spec.InvalidKeySpecException
Generates a private key object from the provided key specification (key material). This class supports the AsciiEncodedKeySpec, RSAPrivateKeySpec, RSAPrivateCrtKeySpec and PKCS8Encoded KeySpec classes.
Throws:
java.security.spec.InvalidKeySpecException - The provided KeySpec was not an AsciiEncodedKeySpec, RSAPrivateKeySpec, RSAPrivateCrtKeySpec or PKCS8EncodedKeySpec KeySpec instance.
Overrides:
engineGeneratePrivate in class java.security.KeyFactorySpi

engineGeneratePublic

protected java.security.PublicKey engineGeneratePublic(java.security.spec.KeySpec keySpec)
                                                throws java.security.spec.InvalidKeySpecException
Generates a public key object from the provided key specification (key material). This class supports the AsciiEncodedKeySpec, RSAPublicKeySpec and X509EncodedKeySpec KeySpec classes.
Throws:
java.security.spec.InvalidKeySpecException - The provided KeySpec was not an AsciiEncodedKeySpec, RSAPublicKeySpec or X509EncodedKeySpec KeySpec.
Overrides:
engineGeneratePublic in class java.security.KeyFactorySpi

engineGetKeySpec

protected java.security.spec.KeySpec engineGetKeySpec(java.security.Key key,
                                                      java.lang.Class spec)
                                               throws java.security.spec.InvalidKeySpecException
Returns a specification (key material) of the given key object. keySpec identifies the specification class in which the key material should be returned. It could, for example, be RSAPublicKeySpec.class, to indicate that the key material should be returned in an instance of the RSAPublicKeySpec class.

Currently supports standard RSA keys and RSAPublicKeySpec, RSAPrivateKeySpec, RSAPrivateCrtKeySpec, X509EncodedKeySpec and PKCS8EncodedKeySpec KeySpec classes.

Parameters:
key - the key the key material is to be recovered from.
spec - the class the new key spec object is meant to be from.
Returns:
the new key spec object representing the key material in key.
Overrides:
engineGetKeySpec in class java.security.KeyFactorySpi

engineTranslateKey

protected java.security.Key engineTranslateKey(java.security.Key key)
                                        throws java.security.InvalidKeyException
Translates a key object, whose provider may be unknown or potentially untrusted, into a corresponding key object of this key factory.

This KeyFactory will convert any key that implements either RSAPrivateCrtKey, RSAPrivateKey, or the RSAPublicKey interface.

Parameters:
key - the key to be translated.
Returns:
the same key, only for this provider.
Overrides:
engineTranslateKey in class java.security.KeyFactorySpi

parseKey

protected static java.math.BigInteger[] parseKey(byte[] keyBytes)
Parse a key from the ABA/PGP format into an array of BigIntegers. The format is:
      modulus.publicExp.privateExp.p.q
 
Parameters:
keyBytes - an ASCII string describing the key.
Returns:
an array of BigIntegers that make up the key.