Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

KeyFactory

extends Object
java.lang.Object
   ↳ java.security.KeyFactory

Class Overview

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.
[Expand]
Inherited Methods
From class java.lang.Object

Protected Constructors

protected KeyFactory ( KeyFactorySpi keyFacSpi, Provider provider, String algorithm)

Added in API level 1

Constructs a new instance of KeyFactory with the specified arguments.

Parameters
keyFacSpi the concrete key factory service.
provider the provider.
algorithm the algorithm to use.

Public Methods

public final PrivateKey generatePrivate ( KeySpec keySpec)

Added in API level 1

Generates a instance of PrivateKey from the given key specification.

Parameters
keySpec the specification of the private key.
Returns
  • the private key.
Throws
InvalidKeySpecException if the specified keySpec is invalid.

public final PublicKey generatePublic ( KeySpec keySpec)

Added in API level 1

Generates a instance of PublicKey from the given key specification.

Parameters
keySpec the specification of the public key
Returns
  • the public key
Throws
InvalidKeySpecException if the specified keySpec is invalid

public final String getAlgorithm ()

Added in API level 1

Returns the name of the algorithm associated with this KeyFactory .

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

public static KeyFactory getInstance ( String algorithm, String provider)

Added in API level 1

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

Parameters
algorithm the name of the algorithm.
provider the name of the provider.
Returns
  • 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()

public static KeyFactory getInstance ( String algorithm, Provider provider)

Added in API level 1

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

Parameters
algorithm the name of the algorithm.
provider the security provider.
Returns
  • 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

public static KeyFactory getInstance ( String algorithm)

Added in API level 1

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

Parameters
algorithm the name of the algorithm.
Returns
  • a new instance of KeyFactory that utilizes the specified algorithm.
Throws
NoSuchAlgorithmException if no provider provides the requested algorithm.
)">

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

Added in API level 1

Returns the key specification for the specified key.

Parameters
key the key from which the specification is requested.
keySpec the type of the requested KeySpec .
Returns
  • 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.

public final Provider getProvider ()

Added in API level 1

Returns the provider associated with this KeyFactory .

Returns
  • the provider associated with this KeyFactory .

public final Key translateKey ( Key key)

Added in API level 1

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

Parameters
key the key to translate.
Returns
  • the translated key.
Throws
InvalidKeyException if the specified key can not be translated by this key factory.