public final class RSAKeyFactory
extends java.security.KeyFactorySpi
To convert, for instance, DER encoded PKCS#8 private key material (e.g. pkcs8_key_spec
instantiated from PKCS8EncodedKeySpec) into RSAPrivateKey representation, use this KeyFactory
for RSA keys:
KeyFactory rsa_key_fac = KeyFactory.getInstance("RSA");
RSAPrivateKey rsa_priv_key = (RSAPrivateKey)rsa_key_fac.generatePrivate(pkcs8_key_spec);
RSAPrivateKey,
RSAPublicKey| Constructor and Description |
|---|
RSAKeyFactory()
Default constructor for creating a RSAKeyFactory.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.security.PrivateKey |
engineGeneratePrivate(java.security.spec.KeySpec keySpec)
Converts the given key specification to a PrivateKey.
|
protected java.security.PublicKey |
engineGeneratePublic(java.security.spec.KeySpec keySpec)
Converts the given key specification to a PublicKey.
|
protected java.security.spec.KeySpec |
engineGetKeySpec(java.security.Key key,
java.lang.Class classSpec)
Converts the given key into the requested key specification (key material).
|
protected java.security.Key |
engineTranslateKey(java.security.Key key)
Translates the given key object of some unknown or untrusted provider into a
key object supported by this RSA key factory.
|
public RSAKeyFactory()
KeyFactory.getInstance("RSA");
for instantiating a RSAKeyFactory.protected java.security.PrivateKey engineGeneratePrivate(java.security.spec.KeySpec keySpec)
throws java.security.spec.InvalidKeySpecException
The given key material may either be a RSAPrivateKeySpec or RSAPrivateKeyCrtSpec, or a PKCS8EncodedKeySpec.
engineGeneratePrivate in class java.security.KeyFactorySpikeySpec - the key specification as RSAPrivateKeySpec, RSAPrivateKeyCrtSpec
or PKCS8EncodedKeySpecjava.security.spec.InvalidKeySpecException - if the given key material is not
a RSAPrivateKeySpec, RSAPrivateKeyCrtSpec or
PKCS8EncodedKeySpecprotected java.security.PublicKey engineGeneratePublic(java.security.spec.KeySpec keySpec)
throws java.security.spec.InvalidKeySpecException
The given key material may either be a RSAPublicKeySpec or a X509EncodedKeySpec.
engineGeneratePublic in class java.security.KeyFactorySpikeySpec - the key specification as RSAPublicKeySpec or X509EncodedKeySpecjava.security.spec.InvalidKeySpecException - if the given key material is not
a RSAPublicKeySpec or X509EncodedKeySpecprotected java.security.spec.KeySpec engineGetKeySpec(java.security.Key key,
java.lang.Class classSpec)
throws java.security.spec.InvalidKeySpecException
The given key may either be a RSAPublicKey or a RSAPrivateKey. If the key is a
RSAPublicKey, this method only can create a RSAPublicKeySpec or a X509EncodedKeySpec
from it. If the given key is a RSAPrivateKey, a RSAPrivateKeySpec, RSAPrivateCrtKeySpec,
or a PKCS8EncodedKeySpec may be returned, depending on which of these types of
specifications is requested by classSpec. Each attempt to get key
material of a type not matching to a given RSA key will raise an exception.
engineGetKeySpec in class java.security.KeyFactorySpikey - the key to be converted, which either may be a RSAPublicKey or a RSAPrivateKey.classSpec - the key specification type into which the key shall be converted, which may be
a RSAPublicKeySpec or a X509EncodedKeySpec if the given key is a RSAPublicKey, or
a RSAPrivateKey(Crt)Spec or a PKCS8EncodedKeySpec if the given key is a
RSAPrivateKeyjava.security.spec.InvalidKeySpecException - if the given key cannot be converted into the
requested key specification object by this key factoryprotected java.security.Key engineTranslateKey(java.security.Key key)
throws java.security.InvalidKeyException
RSAPublicKey or
RSAPrivateKey.engineTranslateKey in class java.security.KeyFactorySpikey - the key of some unknown or untrusted providerjava.security.InvalidKeyException - if the given key cannot be translated by this key factory