APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.security.provider

public abstract Class NamedKeyFactory

extends KeyFactorySpi
Class Inheritance
Known Direct Subclasses
com.sun.crypto.provider.ML_KEM_Impls.KF, sun.security.provider.ML_DSA_Impls.KF
Imports
sun.security.pkcs.NamedPKCS8Key, sun.security.x509.NamedX509Key, java.security.AsymmetricKey, .InvalidKeyException, .Key, .KeyFactorySpi, .PrivateKey, .PublicKey, java.security.spec.EncodedKeySpec, .InvalidKeySpecException, .KeySpec, .NamedParameterSpec, .PKCS8EncodedKeySpec, .X509EncodedKeySpec, java.util.Arrays

A base class for all KeyFactory implementations that can be configured with a named parameter set. See NamedKeyPairGenerator for more details.

This factory supports reading and writing to RAW formats:

  1. It reads from a RAW key using translateKey if key.getFormat is "RAW".
  2. It writes to a RAW EncodedKeySpec if getKeySpec(key, EncodedKeySpec.class) is called. The format of the output is "RAW" and the algorithm is intentionally left unspecified.

When reading from a RAW format, it needs enough info to derive the parameter set name.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final String
private final String[]

Constructor Summary

AccessConstructor and Description
protected
NamedKeyFactory(String
the family name
fname
,
String...
the standard parameter set names, at least one is needed.
pnames
)

Creates a new NamedKeyFactory object.

Method Summary

Modifier and TypeMethod and Description
private String
protected PrivateKey
engineGeneratePrivate(KeySpec keySpec)

Implements abstract java.security.KeyFactorySpi.engineGeneratePrivate.

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

protected PublicKey
engineGeneratePublic(KeySpec 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 key, Class<T> keySpec)

Implements abstract java.security.KeyFactorySpi.engineGetKeySpec.

Returns a specification (key material) of the given key object.

protected Key
engineTranslateKey(Key key)

Implements abstract java.security.KeyFactorySpi.engineTranslateKey.

Translates a key object, whose provider may be unknown or potentially untrusted, into a corresponding key object of this key factory.

private PrivateKey
fromPKCS8(byte[] bytes)

private PrivateKey
fromRaw(String pname, byte[] raw)

private PublicKey
fromX509(byte[] bytes)

protected abstract byte[]

Returns:

the expanded key, not null
implExpand
(String
the parameter set name
pname
,
byte[]
the encoding, could be any format
input
)

User-defined function to generate the expanded format of a NamedPKCS8Key from its encoding format.

protected Key

Field Detail

fnameback to summary
private final String fname
pnamesback to summary
private final String[] pnames

Constructor Detail

NamedKeyFactoryback to summary
protected NamedKeyFactory(String fname, String... pnames)

Creates a new NamedKeyFactory object.

Parameters
fname:String

the family name

pnames:String[]

the standard parameter set names, at least one is needed.

Method Detail

checkNameback to summary
private String checkName(String pname) 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).

Annotations
@Override
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).

Annotations
@Override
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.

Annotations
@Override
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.

Doc from java.security.KeyFactorySpi.engineTranslateKey.

Translates a key object, whose provider may be unknown or potentially untrusted, into a corresponding key object of this key factory.

Annotations
@Override
Exceptions
InvalidKeyException:
if the given key cannot be processed by this key factory.
fromPKCS8back to summary
private PrivateKey fromPKCS8(byte[] bytes) throws InvalidKeyException
fromRawback to summary
private PrivateKey fromRaw(String pname, byte[] raw) throws InvalidKeyException
fromX509back to summary
private PublicKey fromX509(byte[] bytes) throws InvalidKeyException
implExpandback to summary
protected abstract byte[] implExpand(String pname, byte[] input) throws InvalidKeyException

User-defined function to generate the expanded format of a NamedPKCS8Key from its encoding format.

This method is called when the key factory is constructing a private key. The ownership of the result is fully granted to the caller.

Parameters
pname:String

the parameter set name

input:byte[]

the encoding, could be any format

Returns:byte[]

the expanded key, not null

Exceptions
InvalidKeyException:
if input is invalid
toNamedKeyback to summary
protected Key toNamedKey(Key key) throws InvalidKeyException
sun.security.provider back to summary

private Class NamedKeyFactory.RawEncodedKeySpec

extends EncodedKeySpec
Class Inheritance

Constructor Summary

AccessConstructor and Description
public
RawEncodedKeySpec(byte[] encodedKey)

Method Summary

Modifier and TypeMethod and Description
public String
getFormat()

Implements abstract java.security.spec.EncodedKeySpec.getFormat.

Returns the name of the encoding format associated with this key specification.

Inherited from java.security.spec.EncodedKeySpec:
getAlgorithmgetEncoded

Constructor Detail

RawEncodedKeySpecback to summary
public RawEncodedKeySpec(byte[] encodedKey)

Method Detail

getFormatback to summary
public String getFormat()

Implements abstract java.security.spec.EncodedKeySpec.getFormat.

Doc from java.security.spec.EncodedKeySpec.getFormat.

Returns the name of the encoding format associated with this key specification.

If the opaque representation of a key (see Key) can be transformed (see KeyFactory) into this key specification (or a subclass of it), getFormat called on the opaque key returns the same value as the getFormat method of this key specification.

Annotations
@Override