de.flexiprovider.ec.keys
Class ECKeyFactory

java.lang.Object
  |
  +--java.security.KeyFactorySpi
        |
        +--de.flexiprovider.api.keys.KeyFactory
              |
              +--de.flexiprovider.ec.keys.ECKeyFactory

public class ECKeyFactory
extends KeyFactory

Key factories are used to convert keys (opaque cryptographic keys of type Key) into key specifications (transparent representations of the underlying key material), and vice versa.

Key factories are bi-directional. That is, they allow you to build an opaque key object from a given key specification (key material), or to retrieve the underlying key material of a key object in a suitable format.

This class provides the translation between a key specification (ECPrivateKeySpec or ECPublicKeySpec or an ASN.1 / DER- representation, in this case a PKCS8EncodedKeySpec or a X509EncodedKeySpec) and an ECPrivateKey or an ECPublicKey-object.

Author:
Birgit Henhapl, Michele Boivin
See Also:
"java.security.Key", "java.security.KeyFactory", "java.security.spec.KeySpec", "java.security.spec.X509EncodedKeySpec", ECPrivateKeySpec, Point, CurveParams

Field Summary
static java.lang.String OID
          The OID for ECDSA public keys (also used for ECDSA private keys).
 
Constructor Summary
ECKeyFactory()
           
 
Method Summary
 PrivateKey generatePrivate(KeySpec keySpec)
          Generates a private key object from the provided key specification (key material).
 PublicKey generatePublic(KeySpec keySpec)
          Generates a public key object from the provided key specification (key material).
 KeySpec getKeySpec(Key key, java.lang.Class keySpec)
          Returns a specification (key material) of the given key object.
 Key translateKey(Key key)
          Translates a key object, whose provider may be unknown or potentially untrusted, into a corresponding key object of this key factory.
 
Methods inherited from class de.flexiprovider.api.keys.KeyFactory
engineGeneratePrivate, engineGeneratePublic, engineGetKeySpec, engineTranslateKey
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OID

public static final java.lang.String OID
The OID for ECDSA public keys (also used for ECDSA private keys).
   id-publicKeyType   OBJECT IDENTIFIER ::= { ansi-X9-62 keyType(2) }
   id-ecPublicKeyType OBJECT IDENTIFIER ::= { id-publicKeyType 1 }
 
Constructor Detail

ECKeyFactory

public ECKeyFactory()
Method Detail

generatePrivate

public PrivateKey generatePrivate(KeySpec keySpec)
                           throws InvalidKeySpecException
Generates a private key object from the provided key specification (key material).
Overrides:
generatePrivate in class KeyFactory
Parameters:
keySpec - the specification (key material) of the private key
Returns:
the private key
Throws:
InvalidKeySpecException - if the given key specification is inappropriate for this key factory to produce a private key.

generatePublic

public PublicKey generatePublic(KeySpec keySpec)
                         throws InvalidKeySpecException
Generates a public key object from the provided key specification (key material).
Overrides:
generatePublic in class KeyFactory
Parameters:
keySpec - the specification (key material) of the public key
Returns:
the public key
Throws:
InvalidKeySpecException - if the given key specification is inappropriate for this key factory to produce a public key.

getKeySpec

public KeySpec getKeySpec(Key key,
                          java.lang.Class keySpec)
                   throws 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 ECPublicKeySpec.class, to indicate that the key material should be returned in an instance of the ECPublicKeySpec class.
Overrides:
getKeySpec in class KeyFactory
Parameters:
key - the key
keySpec - the specification class in which the key material should be returned
Returns:
the underlying key specification (key material) in an instance of the requested specification class
Throws:
InvalidKeySpecException - if the requested key specification is inappropriate for the given key, or the given key cannot be dealt with (e.g., the given key has an unrecognized format).

translateKey

public Key translateKey(Key key)
                 throws InvalidKeyException
Translates a key object, whose provider may be unknown or potentially untrusted, into a corresponding key object of this key factory.
Overrides:
translateKey in class KeyFactory
Parameters:
key - the key whose provider is unknown or untrusted
Returns:
the translated key
Throws:
InvalidKeyException - if the given key cannot be processed by this key factory.