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
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.
|
[Expand]
Inherited Methods |
From class
java.security.KeyFactorySpi
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait()
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object.
|
final
void
|
wait(long timeout, int nanos)
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.
|
final
void
|
wait(long timeout)
Causes the current thread to wait until either another thread invokes the
notify() method or the
notifyAll() method for this object, or a
specified amount of time has elapsed.
|
|
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 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. |
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. |
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. |
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. |