FileDocCategorySizeDatePackage
KeyPairGenerator.javaAPI DocAndroid 1.5 API10982Wed May 06 22:41:06 BST 2009java.security

KeyPairGenerator

public abstract class KeyPairGenerator extends KeyPairGeneratorSpi
{@code KeyPairGenerator} is an engine class which is capable of generating a private key and its related public key utilizing the algorithm it was initialized with.
see
KeyPairGeneratorSpi
since
Android 1.0

Fields Summary
private static final String
SERVICE
private static org.apache.harmony.security.fortress.Engine
engine
private static SecureRandom
random
private Provider
provider
private String
algorithm
Constructors Summary
protected KeyPairGenerator(String algorithm)
Constructs a new instance of {@code KeyPairGenerator} with the name of the algorithm to use.

param
algorithm the name of algorithm to use
since
Android 1.0


                                               
       
        this.algorithm = algorithm;
    
Methods Summary
public final java.security.KeyPairgenKeyPair()
Computes and returns a new unique {@code KeyPair} each time this method is called.

This does exactly the same as {@link #generateKeyPair()}.

return
a new unique {@code KeyPair} each time this method is called
since
Android 1.0

        return generateKeyPair();
    
public java.security.KeyPairgenerateKeyPair()
Computes and returns a new unique {@code KeyPair} each time this method is called.

This does exactly the same as {@link #genKeyPair()}.

return
a new unique {@code KeyPair} each time this method is called
since
Android 1.0

        return null;
    
public java.lang.StringgetAlgorithm()
Returns the name of the algorithm of this {@code KeyPairGenerator}.

return
the name of the algorithm of this {@code KeyPairGenerator}
since
Android 1.0

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

param
algorithm the name of the algorithm to use
return
a new instance of {@code KeyPairGenerator} that utilizes the specified algorithm
throws
NoSuchAlgorithmException if the specified algorithm is not available
throws
NullPointerException if {@code algorithm} is {@code null}
since
Android 1.0

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

param
algorithm the name of the algorithm to use
param
provider the name of the provider
return
a new instance of {@code KeyPairGenerator} that utilizes the specified algorithm from the specified provider
throws
NoSuchAlgorithmException if the specified algorithm is not available
throws
NoSuchProviderException if the specified provider is not available
throws
NullPointerException if {@code algorithm} is {@code null}
since
Android 1.0

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

param
algorithm the name of the algorithm to use
param
provider the provider
return
a new instance of {@code KeyPairGenerator} that utilizes the specified algorithm from the specified provider
throws
NoSuchAlgorithmException if the specified algorithm is not available
throws
NullPointerException if {@code algorithm} is {@code null}
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$
        }
        KeyPairGenerator result;
        synchronized (engine) {
            engine.getInstance(algorithm, provider, null);
            if (engine.spi instanceof KeyPairGenerator) {
                result = (KeyPairGenerator) engine.spi;
                result.algorithm = algorithm;
                result.provider = provider;
                return result;
            } else {
                result = new KeyPairGeneratorImpl((KeyPairGeneratorSpi) engine.spi,
                        provider, algorithm);
                return result;
            }
        }
    
public final java.security.ProvidergetProvider()
Returns the provider associated with this {@code KeyPairGenerator}.

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

        return provider;
    
public voidinitialize(int keysize, java.security.SecureRandom random)
Initializes this {@code KeyPairGenerator} with the given key size and the given {@code SecureRandom}. The default parameter set will be used.

param
keysize the key size
param
random the source of randomness
since
Android 1.0

    
public voidinitialize(java.security.spec.AlgorithmParameterSpec param, java.security.SecureRandom random)
Initializes this {@code KeyPairGenerator} with the given {@code AlgorithmParameterSpec} and the given {@code SecureRandom}.

param
param the parameters to use
param
random the source of randomness
throws
InvalidAlgorithmParameterException if the specified parameters are not supported
since
Android 1.0

    
public voidinitialize(int keysize)
Initializes this {@code KeyPairGenerator} with the given key size. The default parameter set and a default {@code SecureRandom} instance will be used.

param
keysize the size of the key (number of bits)
since
Android 1.0

        initialize(keysize, random);
    
public voidinitialize(java.security.spec.AlgorithmParameterSpec param)
Initializes this {@code KeyPairGenerator} with the given {@code AlgorithmParameterSpec}. A default {@code SecureRandom} instance will be used.

param
param the parameters to use
throws
InvalidAlgorithmParameterException if the specified parameters are not supported
since
Android 1.0

        initialize(param, random);