javax.crypto

Class SecretKeyFactory


public class SecretKeyFactory
extends Object

A secret key factory translates SecretKey objects to and from KeySpec objects, and can translate between different vendors' representations of SecretKey objects (for security or semantics; whichever applies).
Since:
1.4
See Also:
SecretKey

Constructor Summary

SecretKeyFactory(SecretKeyFactorySpi skfSpi, Provider provider, String algorithm)
Create a new secret key factory.

Method Summary

SecretKey
generateSecret(KeySpec keySpec)
Generate a secret key from a key specification, if possible.
String
getAlgorithm()
Get the algorithm name.
static SecretKeyFactory
getInstance(String algorithm)
Create a new secret key factory from the first appropriate instance.
static SecretKeyFactory
getInstance(String algorithm, String provider)
Create a new secret key factory from the named provider.
static SecretKeyFactory
getInstance(String algorithm, Provider provider)
Create a new secret key factory from the specified provider.
KeySpec
getKeySpec(SecretKey key, Class<T> keySpec)
Get the key specification from a secret key.
Provider
getProvider()
Get the provider of this implementation.
SecretKey
translateKey(SecretKey key)
Translate a secret key into another form.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

SecretKeyFactory

protected SecretKeyFactory(SecretKeyFactorySpi skfSpi,
                           Provider provider,
                           String algorithm)
Create a new secret key factory.
Parameters:
skfSpi - The underlying factory implementation.
provider - The provider.
algorithm - The algorithm name.

Method Details

generateSecret

public final SecretKey generateSecret(KeySpec keySpec)
            throws InvalidKeySpecException
Generate a secret key from a key specification, if possible.
Parameters:
keySpec - The key specification.
Returns:
The secret key.

getAlgorithm

public final String getAlgorithm()
Get the algorithm name.
Returns:
The algorithm name.

getInstance

public static final SecretKeyFactory getInstance(String algorithm)
            throws NoSuchAlgorithmException
Create a new secret key factory from the first appropriate instance.
Parameters:
algorithm - The algorithm name.
Returns:
The appropriate key factory, if found.
Throws:
NoSuchAlgorithmException - If no provider implements the specified algorithm.
IllegalArgumentException - if algorithm is null or is an empty string.

getInstance

public static final SecretKeyFactory getInstance(String algorithm,
                                                 String provider)
            throws NoSuchAlgorithmException,
                   NoSuchProviderException
Create a new secret key factory from the named provider.
Parameters:
algorithm - The algorithm name.
provider - The provider name.
Returns:
The appropriate key factory, if found.
Throws:
NoSuchAlgorithmException - If the named provider does not implement the algorithm.
NoSuchProviderException - If the named provider does not exist.
IllegalArgumentException - if either algorithm or provider is null, or if algorithm is an empty string.

getInstance

public static final SecretKeyFactory getInstance(String algorithm,
                                                 Provider provider)
            throws NoSuchAlgorithmException
Create a new secret key factory from the specified provider.
Parameters:
algorithm - The algorithm name.
provider - The provider.
Returns:
The appropriate key factory, if found.
Throws:
NoSuchAlgorithmException - If the provider does not implement the algorithm.
IllegalArgumentException - if either algorithm or provider is null, or if algorithm is an empty string.

getKeySpec

public final KeySpec getKeySpec(SecretKey key,
                                Class<T> keySpec)
            throws InvalidKeySpecException
Get the key specification from a secret key.
Parameters:
key - The secret key.
keySpec - The target key specification class.
Returns:
The key specification.
Throws:
InvalidKeySpecException - If the secret key cannot be transformed into the specified key specification.

getProvider

public final Provider getProvider()
Get the provider of this implementation.
Returns:
The provider.

translateKey

public final SecretKey translateKey(SecretKey key)
            throws InvalidKeyException
Translate a secret key into another form.
Parameters:
key - The key to translate.
Returns:
The translated key.
Throws:
InvalidKeyException - If the argument cannot be translated.

SecretKeyFactory.java -- Factory for creating secret keys. Copyright (C) 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.