Skip to content

Most visited

Recently visited

navigation
Added in API level 1

KeyFactory

public class KeyFactory
extends Object

java.lang.Object
   ↳ java.security.KeyFactory


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.

Summary

Protected constructors

KeyFactory(KeyFactorySpi keyFacSpi, Provider provider, String algorithm)

Constructs a new instance of KeyFactory with the specified arguments.

Public methods

final PrivateKey generatePrivate(KeySpec keySpec)

Generates a instance of PrivateKey from the given key specification.

final PublicKey generatePublic(KeySpec keySpec)

Generates a instance of PublicKey from the given key specification.

final String getAlgorithm()

Returns the name of the algorithm associated with this KeyFactory.

static KeyFactory getInstance(String algorithm, String provider)

Returns a new instance of KeyFactory that utilizes the specified algorithm from the specified provider.

static KeyFactory getInstance(String algorithm, Provider provider)

Returns a new instance of KeyFactory that utilizes the specified algorithm from the specified provider.

static KeyFactory getInstance(String algorithm)

Returns a new instance of KeyFactory that utilizes the specified algorithm.

final <T extends KeySpec> T getKeySpec(Key key, Class<T> keySpec)

Returns the key specification for the specified key.

final Provider getProvider()

Returns the provider associated with this KeyFactory.

final Key translateKey(Key key)

Translates the given key into a key from this key factory.

Inherited methods

From class java.lang.Object

Protected constructors

KeyFactory

Added in API level 1
KeyFactory (KeyFactorySpi keyFacSpi, 
                Provider provider, 
                String algorithm)

Constructs a new instance of KeyFactory with the specified arguments.

Parameters
keyFacSpi KeyFactorySpi: the concrete key factory service.
provider Provider: the provider.
algorithm String: the algorithm to use.

Public methods

generatePrivate

Added in API level 1
PrivateKey generatePrivate (KeySpec keySpec)

Generates a instance of PrivateKey from the given key specification.

Parameters
keySpec KeySpec: the specification of the private key.
Returns
PrivateKey the private key.
Throws
InvalidKeySpecException if the specified keySpec is invalid.

generatePublic

Added in API level 1
PublicKey generatePublic (KeySpec keySpec)

Generates a instance of PublicKey from the given key specification.

Parameters
keySpec KeySpec: the specification of the public key
Returns
PublicKey the public key
Throws
InvalidKeySpecException if the specified keySpec is invalid

getAlgorithm

Added in API level 1
String getAlgorithm ()

Returns the name of the algorithm associated with this KeyFactory.

Returns
String the name of the algorithm associated with this KeyFactory.

getInstance

Added in API level 1
KeyFactory getInstance (String algorithm, 
                String provider)

Returns a new instance of KeyFactory that utilizes the specified algorithm from the specified provider.

Parameters
algorithm String: the name of the algorithm.
provider String: the name of the provider.
Returns
KeyFactory a new instance of KeyFactory that utilizes the specified algorithm from the specified provider.
Throws
NoSuchAlgorithmException if the provider does not provide the requested algorithm.
NoSuchProviderException if the requested provider is not available.
IllegalArgumentException if provider == null || provider.isEmpty()

getInstance

Added in API level 1
KeyFactory getInstance (String algorithm, 
                Provider provider)

Returns a new instance of KeyFactory that utilizes the specified algorithm from the specified provider. The provider supplied does not have to be registered.

Parameters
algorithm String: the name of the algorithm.
provider Provider: the security provider.
Returns
KeyFactory a new instance of KeyFactory that utilizes the specified algorithm from the specified provider.
Throws
NoSuchAlgorithmException if the provider does not provide the requested algorithm.
IllegalArgumentException if provider == null

getInstance

Added in API level 1
KeyFactory getInstance (String algorithm)

Returns a new instance of KeyFactory that utilizes the specified algorithm.

Parameters
algorithm String: the name of the algorithm.
Returns
KeyFactory a new instance of KeyFactory that utilizes the specified algorithm.
Throws
NoSuchAlgorithmException if no provider provides the requested algorithm.

getKeySpec

Added in API level 1
T getKeySpec (Key key, 
                Class<T> keySpec)

Returns the key specification for the specified key.

Parameters
key Key: the key from which the specification is requested.
keySpec Class: the type of the requested KeySpec.
Returns
T the key specification for the specified key.
Throws
InvalidKeySpecException if the key can not be processed, or the requested requested KeySpec is inappropriate for the given key.

getProvider

Added in API level 1
Provider getProvider ()

Returns the provider associated with this KeyFactory.

Returns
Provider the provider associated with this KeyFactory.

translateKey

Added in API level 1
Key translateKey (Key key)

Translates the given key into a key from this key factory.

Parameters
key Key: the key to translate.
Returns
Key the translated key.
Throws
InvalidKeyException if the specified key can not be translated by this key factory.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.