Top Description Inners Fields Constructors Methods
sun.security.rsa

public Class RSAKeyFactory

extends KeyFactorySpi
Class Inheritance
Known Direct Subclasses
sun.security.rsa.RSAKeyFactory.Legacy, sun.security.rsa.RSAKeyFactory.PSS
Imports
java.math.BigInteger, java.security.*, java.security.interfaces.*, java.security.spec.*, java.util.Arrays, sun.security.action.GetPropertyAction, sun.security.rsa.RSAUtil.KeyType

KeyFactory for RSA keys, e.g. "RSA", "RSASSA-PSS". Keys must be instances of PublicKey or PrivateKey and getAlgorithm() must return a value which matches the type which are specified during construction time of the KeyFactory object. For such keys, it supports conversion between the following: For public keys: . RSA PublicKey with an X.509 encoding . RSA PublicKey with an PKCS#1 encoding . RSAPublicKey . RSAPublicKeySpec . X509EncodedKeySpec For private keys: . RSA PrivateKey with a PKCS#8 encoding . RSA PrivateKey with a PKCS#1 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
Author
Andreas Sterbenz
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
private static final Class<?>
private static final boolean
private static final Class<?>
private static final Class<?>
private static final Class<?>
private final RSAUtil.KeyType
private static final Class<?>

Constructor Summary

AccessConstructor and Description
private
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
checkKeyAlgo(Key key, String expectedAlg)

public static void
checkKeyLengths(int
the bit length of the RSA modulus.
modulusLen
,
BigInteger
the RSA exponent
exponent
,
int
if > 0, check to see if modulusLen is at least this long, otherwise unused.
minModulusLen
,
int
caller will allow this max number of bits. Allow the smaller of the system-defined maximum and this param.
maxModulusLen
)

Check the length of an RSA key modulus/exponent to make sure it is not too short or long.

pack-priv static void
checkRSAProviderKeyLengths(int modulusLen, BigInteger exponent)

protected PrivateKey
engineGeneratePrivate(KeySpec
the specification (key material) of the private key.
keySpec
)

Implements abstract java.security.KeyFactorySpi.engineGeneratePrivate.

Generates a private key object from the provided key specification (key material).
protected PublicKey
engineGeneratePublic(KeySpec
the specification (key material) of the public key.
keySpec
)

Implements abstract java.security.KeyFactorySpi.engineGeneratePublic.

Generates a public key object from the provided key specification (key material).
protected <T extends KeySpec> T
engineGetKeySpec(Key
the key.
key
,
Class<T>
the specification class in which the key material should be returned.
keySpec
)

Implements abstract java.security.KeyFactorySpi.engineGetKeySpec.

Returns a specification (key material) of the given key object.
protected Key
engineTranslateKey(Key
the key whose provider is unknown or untrusted.
key
)

Implements abstract java.security.KeyFactorySpi.engineTranslateKey.

Translate an RSA key into a SunRsaSign RSA key.
private PrivateKey
private PublicKey
pack-priv static RSAKeyFactory
public static RSAKey
toRSAKey(Key key)

Static method to convert Key into an instance of RSAPublicKeyImpl or RSAPrivate(Crt)KeyImpl.

private PrivateKey
private PublicKey

Field Detail

MAX_MODLENback to summary
public static final int MAX_MODLEN
MAX_MODLEN_RESTRICT_EXPback to summary
public static final int MAX_MODLEN_RESTRICT_EXP
MAX_RESTRICTED_EXPLENback to summary
public static final int MAX_RESTRICTED_EXPLEN
MIN_MODLENback to summary
public static final int MIN_MODLEN
PKCS8_KEYSPEC_CLSback to summary
private static final Class<?> PKCS8_KEYSPEC_CLS
restrictExpLenback to summary
private static final boolean restrictExpLen
RSA_PRIV_KEYSPEC_CLSback to summary
private static final Class<?> RSA_PRIV_KEYSPEC_CLS
RSA_PRIVCRT_KEYSPEC_CLSback to summary
private static final Class<?> RSA_PRIVCRT_KEYSPEC_CLS
RSA_PUB_KEYSPEC_CLSback to summary
private static final Class<?> RSA_PUB_KEYSPEC_CLS
typeback to summary
private final RSAUtil.KeyType type
X509_KEYSPEC_CLSback to summary
private static final Class<?> X509_KEYSPEC_CLS

Constructor Detail

RSAKeyFactoryback to summary
private RSAKeyFactory()
RSAKeyFactoryback to summary
public RSAKeyFactory(RSAUtil.KeyType type)

Method Detail

checkKeyAlgoback to summary
pack-priv static void checkKeyAlgo(Key key, String expectedAlg) throws InvalidKeyException
checkKeyLengthsback to summary
public static void checkKeyLengths(int modulusLen, BigInteger exponent, int minModulusLen, int maxModulusLen) throws InvalidKeyException

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:int

the bit length of the RSA modulus.

exponent:BigInteger

the RSA exponent

minModulusLen:int

if > 0, check to see if modulusLen is at least this long, otherwise unused.

maxModulusLen:int

caller will allow this max number of bits. Allow the smaller of the system-defined maximum and this param.

Exceptions
InvalidKeyException:
if any of the values are unacceptable.
checkRSAProviderKeyLengthsback to summary
pack-priv static void checkRSAProviderKeyLengths(int modulusLen, BigInteger exponent) throws InvalidKeyException
engineGeneratePrivateback to summary
protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException

Implements abstract java.security.KeyFactorySpi.engineGeneratePrivate.

Doc from java.security.KeyFactorySpi.engineGeneratePrivate.

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

Parameters
keySpec:KeySpec

the specification (key material) of the private key.

Returns:PrivateKey

the private key.

Exceptions
InvalidKeySpecException:
if the given key specification is inappropriate for this key factory to produce a private key.
engineGeneratePublicback to summary
protected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException

Implements abstract java.security.KeyFactorySpi.engineGeneratePublic.

Doc from java.security.KeyFactorySpi.engineGeneratePublic.

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

Parameters
keySpec:KeySpec

the specification (key material) of the public key.

Returns:PublicKey

the public key.

Exceptions
InvalidKeySpecException:
if the given key specification is inappropriate for this key factory to produce a public key.
engineGetKeySpecback to summary
protected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException

Implements abstract java.security.KeyFactorySpi.engineGetKeySpec.

Doc from java.security.KeyFactorySpi.engineGetKeySpec.

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
<T>
the type of the key specification to be returned
key:Key

the key.

keySpec:Class<T>

the specification class in which the key material should be returned.

Returns:T

the underlying key specification (key material) in an instance of the requested specification class.

Exceptions
InvalidKeySpecException:
if the requested key specification is inappropriate for the given key, or the given key cannot be dealt with (e.g., the given key has an unrecognized format).
engineTranslateKeyback to summary
protected Key engineTranslateKey(Key key) throws InvalidKeyException

Implements abstract java.security.KeyFactorySpi.engineTranslateKey.

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

Parameters
key:Key

Doc from java.security.KeyFactorySpi.engineTranslateKey.

the key whose provider is unknown or untrusted.

Returns:Key

Doc from java.security.KeyFactorySpi.engineTranslateKey.

the translated key.

Exceptions
InvalidKeyException:

Doc from java.security.KeyFactorySpi.engineTranslateKey.

if the given key cannot be processed by this key factory.

generatePrivateback to summary
private PrivateKey generatePrivate(KeySpec keySpec) throws GeneralSecurityException
generatePublicback to summary
private PublicKey generatePublic(KeySpec keySpec) throws GeneralSecurityException
getInstanceback to summary
pack-priv static RSAKeyFactory getInstance(RSAUtil.KeyType type)
toRSAKeyback to summary
public static RSAKey toRSAKey(Key key) throws InvalidKeyException

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.

translatePrivateKeyback to summary
private PrivateKey translatePrivateKey(PrivateKey key) throws InvalidKeyException
translatePublicKeyback to summary
private PublicKey translatePublicKey(PublicKey key) throws InvalidKeyException
sun.security.rsa back to summary

public final Class RSAKeyFactory.Legacy

extends RSAKeyFactory
Class Inheritance

Field Summary

Inherited from sun.security.rsa.RSAKeyFactory:
MAX_MODLENMAX_MODLEN_RESTRICT_EXPMAX_RESTRICTED_EXPLENMIN_MODLEN

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from sun.security.rsa.RSAKeyFactory:
checkKeyAlgocheckKeyLengthscheckRSAProviderKeyLengthsengineGeneratePrivateengineGeneratePublicengineGetKeySpecengineTranslateKeygetInstancetoRSAKey

Constructor Detail

Legacyback to summary
public Legacy()
sun.security.rsa back to summary

public final Class RSAKeyFactory.PSS

extends RSAKeyFactory
Class Inheritance

Field Summary

Inherited from sun.security.rsa.RSAKeyFactory:
MAX_MODLENMAX_MODLEN_RESTRICT_EXPMAX_RESTRICTED_EXPLENMIN_MODLEN

Constructor Summary

AccessConstructor and Description
public
PSS()

Method Summary

Inherited from sun.security.rsa.RSAKeyFactory:
checkKeyAlgocheckKeyLengthscheckRSAProviderKeyLengthsengineGeneratePrivateengineGeneratePublicengineGetKeySpecengineTranslateKeygetInstancetoRSAKey

Constructor Detail

PSSback to summary
public PSS()