Final

java.security
Class KeyFactory

java.lang.Object
  |
  +--java.security.KeyFactory

public class KeyFactory
extends Object

Instances of this class are used to convert back and forth between keys and key specifications.


Constructor Summary
protected KeyFactory(KeyFactorySpi keyFactorySpi, Provider provider, String algName)
          Constructs a new instance of this class with the given implementation, provider and named algorithm.
 
Method Summary
 PrivateKey generatePrivate(KeySpec keySpec)
          Generates a private key for the given key specification.
 PublicKey generatePublic(KeySpec keySpec)
          Generates a public key for the given key specification.
 String getAlgorithm()
          Answers the standard Java Security name for the algorithm being used by the receiver.
static KeyFactory getInstance(String algorithmName)
          Answers a new KeyFactory which is capable of running the algorithm described by the argument.
static KeyFactory getInstance(String algorithm, Provider provider)
          Answers a new KeyFactory which is capable of running the algorithm described by the argument.
static KeyFactory getInstance(String algorithmName, String providerName)
          Answers a new KeyFactory which is capable of running the algorithm described by the argument.
 KeySpec getKeySpec(Key key, Class keySpec)
          Answers a key specification for a given key.
 Provider getProvider()
          Returns the Provider of the key factory represented by the receiver.
 Key translateKey(Key key)
          Translates a generic key (any provider, trusted or not) to an instance of this key factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyFactory

protected KeyFactory(KeyFactorySpi keyFactorySpi,
                     Provider provider,
                     String algName)
Constructs a new instance of this class with the given implementation, provider and named algorithm.

Parameters:
keyFactorySpi - KeyFactorySpi The actual key factory implementation.
provider - Provider The provider of the key factory.
algName - String Algorithm name.
Method Detail

generatePrivate

public final PrivateKey generatePrivate(KeySpec keySpec)
                                 throws InvalidKeySpecException
Generates a private key for the given key specification.

Parameters:
keySpec - KeySpec the key specification to be used for key generation.
Throws:
InvalidKeySpecException - if the provided key specification is not appropriate

getAlgorithm

public final String getAlgorithm()
Answers the standard Java Security name for the algorithm being used by the receiver.

Returns:
String the name of the algorithm

getInstance

public static KeyFactory getInstance(String algorithmName,
                                     String providerName)
                              throws NoSuchAlgorithmException,
                                     NoSuchProviderException
Answers a new KeyFactory which is capable of running the algorithm described by the argument. The result will be an instance of KeyFactory which implements that algorithm.

Parameters:
algorithmName - java.lang.String Name of the algorithm desired
providerName - java.lang.String Name of the provider which has to implement the algorithm
Returns:
KeyFactory a concrete implementation for the algorithm desired.
Throws:
NoSuchAlgorithmException - If the algorithm cannot be found
NoSuchProviderException - If the provider cannot be found

getInstance

public static KeyFactory getInstance(String algorithm,
                                     Provider provider)
                              throws NoSuchAlgorithmException
Answers a new KeyFactory which is capable of running the algorithm described by the argument. The result will be an instance of KeyFactory which implements that algorithm.

Parameters:
algorithm - java.lang.String Name of the algorithm desired
provider - Provider Provider which has to implement the algorithm
Returns:
KeyFactory a concrete implementation for the algorithm desired.
Throws:
NoSuchAlgorithmException - If the algorithm cannot be found

getKeySpec

public final KeySpec getKeySpec(Key key,
                                Class keySpec)
                         throws InvalidKeySpecException
Answers a key specification for a given key.

Parameters:
key - Key the key for which the specification is to be computed.
keySpec - Class the class of the result specification
Returns:
a key specification for a given key. The class of the result object will be keySpec.
Throws:
InvalidKeySpecException - if the provided key specification is not appropriate

getProvider

public final Provider getProvider()
Returns the Provider of the key factory represented by the receiver.

Returns:
Provider an instance of a subclass of java.security.Provider

translateKey

public final Key translateKey(Key key)
                       throws InvalidKeyException
Translates a generic key (any provider, trusted or not) to an instance of this key factory.

Parameters:
key - Key the key for which the new key is to be computed.
Returns:
a key for the given key.
Throws:
InvalidKeyException - if the specified key is not valid (improperly encoded, parameters missing, etc)

generatePublic

public final PublicKey generatePublic(KeySpec keySpec)
                               throws InvalidKeySpecException
Generates a public key for the given key specification.

Parameters:
keySpec - KeySpec the key specification to be used for key generation.
Throws:
InvalidKeySpecException - if the provided key specification is not appropriate

getInstance

public static KeyFactory getInstance(String algorithmName)
                              throws NoSuchAlgorithmException
Answers a new KeyFactory which is capable of running the algorithm described by the argument. The result will be an instance of KeyFactory which implements that algorithm.

Parameters:
algorithmName - java.lang.String Name of the algorithm desired
Returns:
KeyFactory a concrete implementation for the algorithm desired.
Throws:
NoSuchAlgorithmException - If the algorithm cannot be found

Final

Licensed Materials - Property of IBM
(C) Copyright IBM Corp. 2006 All Rights Reserved.