FileDocCategorySizeDatePackage
KeyGenerator.javaAPI DocAndroid 1.5 API9249Wed May 06 22:41:02 BST 2009javax.crypto

KeyGenerator

public class KeyGenerator extends Object
This class provides the public API for generating symmetric cryptographic keys.
since
Android 1.0

Fields Summary
private static final org.apache.harmony.security.fortress.Engine
engine
private static final SecureRandom
rndm
private final Provider
provider
private final KeyGeneratorSpi
spiImpl
private final String
algorithm
Constructors Summary
protected KeyGenerator(KeyGeneratorSpi keyGenSpi, Provider provider, String algorithm)
Creates a new {@code KeyGenerator} instance.

param
keyGenSpi the implementation delegate.
param
provider the implementation provider.
param
algorithm the name of the algorithm.
since
Android 1.0


                                                                     
        
              
        this.provider = provider;
        this.algorithm = algorithm;
        this.spiImpl = keyGenSpi;
    
Methods Summary
public final javax.crypto.SecretKeygenerateKey()
Generates a secret key.

return
the generated secret key.
since
Android 1.0

        return spiImpl.engineGenerateKey();
    
public final java.lang.StringgetAlgorithm()
Returns the name of the key generation algorithm.

return
the name of the key generation algorithm.
since
Android 1.0

        return algorithm;
    
public static final javax.crypto.KeyGeneratorgetInstance(java.lang.String algorithm)
Creates a new {@code KeyGenerator} instance that provides the specified key algorithm,

param
algorithm the name of the requested key algorithm
return
the new {@code KeyGenerator} instance.
throws
NoSuchAlgorithmException if the specified algorithm is not available by any provider.
throws
NullPointerException if {@code algorithm} is {@code null}.
since
Android 1.0

        if (algorithm == null) {
            throw new NullPointerException(Messages.getString("crypto.02")); //$NON-NLS-1$
        }
        synchronized (engine) {
            engine.getInstance(algorithm, null);
            return new KeyGenerator((KeyGeneratorSpi) engine.spi, engine.provider,
                    algorithm);
        }
    
public static final javax.crypto.KeyGeneratorgetInstance(java.lang.String algorithm, java.lang.String provider)
Creates a new {@code KeyGenerator} instance that provides the specified key algorithm from the specified provider.

param
algorithm the name of the requested key algorithm.
param
provider the name of the provider that is providing the algorithm.
return
the new {@code KeyGenerator} instance.
throws
NoSuchAlgorithmException if the specified algorithm is not provided by the specified provider.
throws
NoSuchProviderException if the specified provider is not available.
throws
IllegalArgumentException if the specified provider is name is {@code null} or empty.
throws
NullPointerException if the specified algorithm name is {@code null}.
since
Android 1.0

        if ((provider == null) || (provider.length() == 0)) {
            throw new IllegalArgumentException(Messages.getString("crypto.03")); //$NON-NLS-1$
        }
        Provider impProvider = Security.getProvider(provider);
        if (impProvider == null) {
            throw new NoSuchProviderException(provider);
        }
        return getInstance(algorithm, impProvider);
    
public static final javax.crypto.KeyGeneratorgetInstance(java.lang.String algorithm, java.security.Provider provider)
Creates a new {@code KeyGenerator} instance that provides the specified key algorithm from the specified provider.

param
algorithm the name of the requested key algorithm.
param
provider the provider that is providing the algorithm
return
the new {@code KeyGenerator} instance.
throws
NoSuchAlgorithmException if the specified algorithm is not provided by the specified provider.
throws
IllegalArgumentException if the specified provider is {@code null}.
throws
NullPointerException if the specified algorithm name is {@code null}.
since
Android 1.0

        if (provider == null) {
            throw new IllegalArgumentException(Messages.getString("crypto.04")); //$NON-NLS-1$
        }
        if (algorithm == null) {
            throw new NullPointerException(Messages.getString("crypto.02")); //$NON-NLS-1$
        }
        synchronized (engine) {
            engine.getInstance(algorithm, provider, null);
            return new KeyGenerator((KeyGeneratorSpi) engine.spi, provider,
                    algorithm);
        }
    
public final java.security.ProvidergetProvider()
Returns the provider of this {@code KeyGenerator} instance.

return
the provider of this {@code KeyGenerator} instance.
since
Android 1.0

        return provider;
    
public final voidinit(int keysize)
Initializes this {@code KeyGenerator} instance for the specified key size (in bits).

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

        spiImpl.engineInit(keysize, rndm);//new SecureRandom());
    
public final voidinit(int keysize, java.security.SecureRandom random)
Initializes this {@code KeyGenerator} instance for the specified key size (in bits) using the specified randomness source.

param
keysize the size of the key (in bits).
param
random the randomness source for any random bytes.
since
Android 1.0

        spiImpl.engineInit(keysize, random);
    
public final voidinit(java.security.SecureRandom random)
Initializes this {@code KeyGenerator} with the specified randomness source.

param
random the randomness source for any random bytes.
since
Android 1.0

        spiImpl.engineInit(random);
    
public final voidinit(java.security.spec.AlgorithmParameterSpec params)
Initializes this {@code KeyGenerator} instance with the specified algorithm parameters.

param
params the parameters for the key generation algorithm.
throws
InvalidAlgorithmParameterException if the parameters cannot be used to initialize this key generator algorithm.
since
Android 1.0

        spiImpl.engineInit(params, rndm);//new SecureRandom());
    
public final voidinit(java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)
Initializes this {@code KeyGenerator} instance with the specified algorithm parameters and randomness source.

param
params the parameters for the key generation algorithm.
param
random the randomness source for any random bytes.
throws
InvalidAlgorithmParameterException if the parameters cannot be uses to initialize this key generator algorithm.
since
Android 1.0

        spiImpl.engineInit(params, random);