public final class

RSAKeyFactory

extends KeyFactorySpi
java.lang.Object
   ↳ java.security.KeyFactorySpi
     ↳ sun.security.rsa.RSAKeyFactory

Class Overview

KeyFactory for RSA keys. Keys must be instances of PublicKey or PrivateKey and getAlgorithm() must return "RSA". For such keys, it supports conversion between the following: For public keys: . PublicKey with an X.509 encoding . RSAPublicKey . RSAPublicKeySpec . X509EncodedKeySpec For private keys: . PrivateKey with a PKCS#8 encoding . RSAPrivateKey . RSAPrivateCrtKey . RSAPrivateKeySpec . RSAPrivateCrtKeySpec . PKCS8EncodedKeySpec (of course, CRT variants only for CRT keys) Note: as always, RSA keys should be at least 512 bits long

Summary

Constants
int MAX_MODLEN
int MAX_MODLEN_RESTRICT_EXP
int MAX_RESTRICTED_EXPLEN
int MIN_MODLEN
Public Constructors
RSAKeyFactory()
Public Methods
static void checkKeyLengths(int modulusLen, BigInteger exponent, int minModulusLen, int maxModulusLen)
Check the length of an RSA key modulus/exponent to make sure it is not too short or long.
static RSAKey toRSAKey(Key key)
Static method to convert Key into an instance of RSAPublicKeyImpl or RSAPrivate(Crt)KeyImpl.
Protected Methods
PrivateKey engineGeneratePrivate(KeySpec keySpec)
Generates a private key object from the provided key specification (key material).
PublicKey engineGeneratePublic(KeySpec keySpec)
Generates a public key object from the provided key specification (key material).
<T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec)
Returns a specification (key material) of the given key object.
Key engineTranslateKey(Key key)
Translate an RSA key into a SunRsaSign RSA key.
[Expand]
Inherited Methods
From class java.security.KeyFactorySpi
From class java.lang.Object

Constants

public static final int MAX_MODLEN

Constant Value: 16384 (0x00004000)

public static final int MAX_MODLEN_RESTRICT_EXP

Constant Value: 3072 (0x00000c00)

public static final int MAX_RESTRICTED_EXPLEN

Constant Value: 64 (0x00000040)

public static final int MIN_MODLEN

Constant Value: 512 (0x00000200)

Public Constructors

public RSAKeyFactory ()

Public Methods

public static void checkKeyLengths (int modulusLen, BigInteger exponent, int minModulusLen, int maxModulusLen)

Check the length of an RSA key modulus/exponent to make sure it is not too short or long. Some impls have their own min and max key sizes that may or may not match with a system defined value.

Parameters
modulusLen the bit length of the RSA modulus.
exponent the RSA exponent
minModulusLen if > 0, check to see if modulusLen is at least this long, otherwise unused.
maxModulusLen caller will allow this max number of bits. Allow the smaller of the system-defined maximum and this param.
Throws
InvalidKeyException if any of the values are unacceptable.

public static RSAKey toRSAKey (Key key)

Static method to convert Key into an instance of RSAPublicKeyImpl or RSAPrivate(Crt)KeyImpl. If the key is not an RSA key or cannot be used, throw an InvalidKeyException. Used by RSASignature and RSACipher.

Protected Methods

protected PrivateKey engineGeneratePrivate (KeySpec keySpec)

Generates a private key object from the provided key specification (key material).

Parameters
keySpec the specification (key material) of the private key.
Returns
  • the private key.

protected PublicKey engineGeneratePublic (KeySpec keySpec)

Generates a public key object from the provided key specification (key material).

Parameters
keySpec the specification (key material) of the public key.
Returns
  • the public key.

protected T engineGetKeySpec (Key key, Class<T> keySpec)

Returns a specification (key material) of the given key object. keySpec identifies the specification class in which the key material should be returned. It could, for example, be DSAPublicKeySpec.class, to indicate that the key material should be returned in an instance of the DSAPublicKeySpec class.

Parameters
key the key.
keySpec the specification class in which the key material should be returned.
Returns
  • the underlying key specification (key material) in an instance of the requested specification class.

protected Key engineTranslateKey (Key key)

Translate an RSA key into a SunRsaSign RSA key. If conversion is not possible, throw an InvalidKeyException. See also JCA doc.

Parameters
key the key whose provider is unknown or untrusted.
Returns
  • the translated key.