FileDocCategorySizeDatePackage
KeyFactory.javaAPI DocAndroid 1.5 API8713Wed May 06 22:41:06 BST 2009java.security

KeyFactory

public class KeyFactory extends Object
{@code KeyFactory} is an engine class that can be used to translate between public and private key objects and convert keys between their external representation, that can be easily transported and their internal representation.
since
Android 1.0

Fields Summary
private static final String
SERVICE
private Provider
provider
private static org.apache.harmony.security.fortress.Engine
engine
private KeyFactorySpi
spiImpl
private String
algorithm
Constructors Summary
protected KeyFactory(KeyFactorySpi keyFacSpi, Provider provider, String algorithm)
Constructs a new instance of {@code KeyFactory} with the specified arguments.

param
keyFacSpi the concrete key factory service.
param
provider the provider.
param
algorithm the algorithm to use.
since
Android 1.0


                                                                          
       
                          
                           
        this.provider = provider;
        this. algorithm = algorithm;
        this.spiImpl = keyFacSpi;
    
Methods Summary
public final java.security.PrivateKeygeneratePrivate(java.security.spec.KeySpec keySpec)
Generates a instance of {@code PrivateKey} from the given key specification.

param
keySpec the specification of the private key.
return
the private key.
throws
InvalidKeySpecException if the specified {@code keySpec} is invalid.
since
Android 1.0

        return spiImpl.engineGeneratePrivate(keySpec);
    
public final java.security.PublicKeygeneratePublic(java.security.spec.KeySpec keySpec)
Generates a instance of {@code PublicKey} from the given key specification.

param
keySpec the specification of the public key
return
the public key
throws
InvalidKeySpecException if the specified {@code keySpec} is invalid
since
Android 1.0

        return spiImpl.engineGeneratePublic(keySpec);
    
public final java.lang.StringgetAlgorithm()
Returns the name of the algorithm associated with this {@code KeyFactory} .

return
the name of the algorithm associated with this {@code KeyFactory} .
since
Android 1.0

        return algorithm;
    
public static java.security.KeyFactorygetInstance(java.lang.String algorithm)
Returns a new instance of {@code KeyFactory} that utilizes the specified algorithm.

param
algorithm the name of the algorithm.
return
a new instance of {@code KeyFactory} that utilizes the specified algorithm.
throws
NoSuchAlgorithmException if no provider provides the requested algorithm.
since
Android 1.0

        if (algorithm == null) {
            throw new NullPointerException(Messages.getString("security.01")); //$NON-NLS-1$
        }
        synchronized (engine) {
            engine.getInstance(algorithm, null);
            return new KeyFactory((KeyFactorySpi)engine.spi, engine.provider, algorithm);
        }
    
public static java.security.KeyFactorygetInstance(java.lang.String algorithm, java.lang.String provider)
Returns a new instance of {@code KeyFactory} that utilizes the specified algorithm from the specified provider.

param
algorithm the name of the algorithm.
param
provider the name of the provider.
return
a new instance of {@code KeyFactory} that utilizes the specified algorithm from the specified provider.
throws
NoSuchAlgorithmException if the provider does not provide the requested algorithm.
throws
NoSuchProviderException if the requested provider is not available.
throws
IllegalArgumentException if {@code provider} is {@code null} or empty.
since
Android 1.0

        if ((provider == null) || (provider.length() == 0)) {
            throw new IllegalArgumentException(Messages.getString("security.02")); //$NON-NLS-1$
        }
        Provider p = Security.getProvider(provider);
        if (p == null) {
            throw new NoSuchProviderException(Messages.getString("security.03", provider));  //$NON-NLS-1$ //$NON-NLS-2$
        }
        return getInstance(algorithm, p);    
    
public static java.security.KeyFactorygetInstance(java.lang.String algorithm, java.security.Provider provider)
Returns a new instance of {@code KeyFactory} that utilizes the specified algorithm from the specified provider.

param
algorithm the name of the algorithm.
param
provider the security provider.
return
a new instance of {@code KeyFactory} that utilizes the specified algorithm from the specified provider.
throws
NoSuchAlgorithmException if the provider does not provide the requested algorithm.
since
Android 1.0

        if (provider == null) {
            throw new IllegalArgumentException(Messages.getString("security.04")); //$NON-NLS-1$
        }
        if (algorithm == null) {
            throw new NullPointerException(Messages.getString("security.01")); //$NON-NLS-1$
        }
        synchronized (engine) {
            engine.getInstance(algorithm, provider, null);
            return new KeyFactory((KeyFactorySpi)engine.spi, provider, algorithm);
        }
    
public final TgetKeySpec(java.security.Key key, java.lang.Class keySpec)
Returns the key specification for the specified key.

param
key the key from which the specification is requested.
param
keySpec the type of the requested {@code KeySpec}.
return
the key specification for the specified key.
throws
InvalidKeySpecException if the key can not be processed, or the requested requested {@code KeySpec} is inappropriate for the given key.
since
Android 1.0

        return spiImpl.engineGetKeySpec(key, keySpec);
    
public final java.security.ProvidergetProvider()
Returns the provider associated with this {@code KeyFactory}.

return
the provider associated with this {@code KeyFactory}.
since
Android 1.0

        return provider;
    
public final java.security.KeytranslateKey(java.security.Key key)
Translates the given key into a key from this key factory.

param
key the key to translate.
return
the translated key.
throws
InvalidKeyException if the specified key can not be translated by this key factory.
since
Android 1.0

        return spiImpl.engineTranslateKey(key);