public final class RSAOaepKeyFactory
extends java.security.KeyFactorySpi
RSAOaepPublicKey
into a
java.security.spec.X509EncodedKeySpec
representing the public
key in DER encoded format (and vice versa):
RSAOaepPublicKey publicKey = ...; KeyFactory kf = KeyFactory.getInstance("RSAES-OAEP", "IAIK"); X509EncodedKeySpec x509KeySpec = (X509EncodedKeySpec)kf.getKeySpec(publicKey, X509EncodedKeySpec.class); byte[] encodedKey = x509KeySpec.getEncoded();respectively:
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(encodedKey); KeyFactory kf = KeyFactory.getInstance("RSAES-OAEP", "IAIK"); RSAOaepPublicKey publicKey = (RSAOaepPublicKey) kf.generatePublic(x509KeySpec);A
RSAOaepPrivateKey
can be
converted into a java.security.spec.PKCS8EncodedKeySpec
(and
vice versa):
RSAOaepPrivateKey privateKey = ...; KeyFactory kf = KeyFactory.getInstance("RSAES-OAEP", "IAIK"); PKCS8EncodedKeySpec pkcs8KeySpec = (PKCS8EncodedKeySpec)kf.getKeySpec(privateKey, PKCS8EncodedKeySpec.class); byte[] encodedKey = pkcs8KeySpec.getEncoded();respectively:
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(encodedKey); KeyFactory kf = KeyFactory.getInstance("RSAES-OAEP", "IAIK"); RSAOaepPrivateKey privateKey = (RSAOaepPrivateKey) kf .generatePublic(pkcs8KeySpec);
RSAOaepPublicKey
,
RSAOaepPrivateKey
,
RSAOaepKeyPairGenerator
,
KeyFactory
,
X509EncodedKeySpec
,
PKCS8EncodedKeySpec
Constructor and Description |
---|
RSAOaepKeyFactory()
Default constructor for creating a RSAOaepKeyFactory.
|
Modifier and Type | Method and Description |
---|---|
protected java.security.PrivateKey |
engineGeneratePrivate(java.security.spec.KeySpec keySpec)
Converts the given key specification to a RSAOaepPrivateKey.
|
protected java.security.PublicKey |
engineGeneratePublic(java.security.spec.KeySpec keySpec)
Converts the given key specification to a RSAOaepPublicKey.
|
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 RSAOaepKeyFactory()
for instantiating a RSAKeyFactory.KeyFactory.getInstance("RSAES-OAEP", "IAIK");
protected java.security.PrivateKey engineGeneratePrivate(java.security.spec.KeySpec keySpec) throws java.security.spec.InvalidKeySpecException
The given KeySpec must be a PKCS8EncodedKeySpec representing the RSAES-OAEP key as DER encoded byte material.
engineGeneratePrivate
in class java.security.KeyFactorySpi
keySpec
- the key specification as PKCS8EncodedKeySpecjava.security.spec.InvalidKeySpecException
- if the given key material is not a PKCS8EncodedKeySpec or a
decoding error occursprotected java.security.PublicKey engineGeneratePublic(java.security.spec.KeySpec keySpec) throws java.security.spec.InvalidKeySpecException
The given KeySpec must be a X509EncodedKeySpec representing the RSAES-OAEP key as DER encoded byte material.
engineGeneratePublic
in class java.security.KeyFactorySpi
keySpec
- the key specification as X509EncodedKeySpecjava.security.spec.InvalidKeySpecException
- if the given key material is not a X509EncodedKeySpec or a
decoding error occursprotected 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 RSAOaepPublicKey or a RSAOaepPrivateKey. If the key is a RSAOaepPublicKey, this method only can create a X509EncodedKeySpec representing the key as DER encoded byte material. If the given key is a RSAOaepPrivateKey, this method only can create a PKCS8EncodedKeySpec representing the key as DER encoded byte material.
engineGetKeySpec
in class java.security.KeyFactorySpi
key
- the key to be converted, which either may be a RSAOaepPublicKey or
a RSAOaepPrivateKey.classSpec
- the key specification type into which the key shall be converted,
which may be X509EncodedKeySpec if the given key is a
RSAOaepPublicKey, or a PKCS8EncodedKeySpec if the given key is a
RSAOaepPrivateKeyjava.security.spec.InvalidKeySpecException
- if the given key cannot be converted into the requested key
specification object by this key factory (i.e. if the given
key is not a RSAOaepPublicKey or a RSAOaepPrivateKey, or the
requested keySpec is not a X509EncodedKeySpec or a
PKCS8EncodedKeySpecprotected java.security.Key engineTranslateKey(java.security.Key key) throws java.security.InvalidKeyException
RSAOaepPublicKey
or
RSAOaepPrivateKey
.engineTranslateKey
in class java.security.KeyFactorySpi
key
- the key of some unknown or untrusted providerjava.security.InvalidKeyException
- if the given key cannot be translated by this key factory