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

public final Class NamedPKCS8Key

extends PKCS8Key
Class Inheritance
Imports
sun.security.x509.AlgorithmId, java.io.IOException, .InvalidObjectException, .ObjectInputStream, .Serial, java.security.InvalidKeyException, .NoSuchAlgorithmException, .ProviderException, java.security.spec.NamedParameterSpec, java.util.Arrays, .Objects

Represents a private key from an algorithm family that is specialized with a named parameter set.

This key is generated by either a sun.security.provider.NamedKeyPairGenerator or sun.security.provider.NamedKeyFactory. Its getAlgorithm method returns the algorithm family name, while its getParams() method returns the parameter set name as a NamedParameterSpec object. The algorithm identifier in the PKCS #8 encoding of the key is always a single OID derived from the parameter set name.

Besides the existing PKCS8Key#privKeyMaterial field, this class optionally supports an expanded format stored in expanded. While privKeyMaterial always represents the format used for encoding, expanded is always used in computations. The expanded format must be self-sufficient for cryptographic computations without requiring the encoding format.

  1. If only privKeyMaterial is present, it's also the expanded format.
  2. If both privKeyMaterial and expanded are available, privKeyMaterial is the encoding format, and expanded is the expanded format.

If the two formats are the same, only privKeyMaterial is included, and expanded must be null. Some implementations might be tempted to put the same value into privKeyMaterial and expanded. However, problems can arise if they happen to be the same object. To avoid ambiguity, always set expanded to null.

If the expanded field is required by the algorithm, it is either calculated from the PKCS #8 encoding, or provided directly. In the latter case, the caller must ensure the consistency of the encoded and expanded arguments. For example, seed and expanded key must match.

See Also
sun.security.provider.NamedKeyPairGenerator

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
NamedPKCS8Key.Expander

Expands from encoding format to expanded format.

Field Summary

Modifier and TypeField and Description
private transient boolean
private final transient byte[]
private final String
private final transient NamedParameterSpec
private static final long
Inherited from sun.security.pkcs.PKCS8Key:
algidencodedKeyprivKeyMaterialpubKeyEncodedV1V2

Constructor Summary

AccessConstructor and Description
private
NamedPKCS8Key(String
family name
fname
,
String
parameter set name
pname
,
byte[]
raw key bytes, not null
encoded
,
byte[]
expanded key format, can be null.
expanded
)

Creates a NamedPKCS8Key from raw components.

public
NamedPKCS8Key(String
family name
fname
,
byte[]
PKCS #8 encoding. It is copied so caller can modify it after the method call.
encoded
,
NamedPKCS8Key.Expander
a function that is able to calculate the expanded format from the encoding format inside encoded. If it recognizes the input already in expanded format, it must return null. This argument must be null if the algorithm's expanded format is always the same as its encoding format. Whatever the case, the ownership of the result is fully granted to this object.
expander
)

Creates a NamedPKCS8Key from family name and PKCS #8 encoding.

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Overrides default javax.security.auth.Destroyable.destroy.

Destroy this Object.

public String
getAlgorithm()

Overrides sun.security.pkcs.PKCS8Key.getAlgorithm.

Implements java.security.Key.getAlgorithm.

Returns the algorithm to be used with this key.

public byte[]
getExpanded()

Returns the reference to the key in expanded format.

public NamedParameterSpec
getParams()

Overrides default java.security.AsymmetricKey.getParams.

Returns the parameters associated with this key.

public byte[]
getRawBytes()

Returns the reference to the internal key.

public static NamedPKCS8Key
internalCreate(String
family name
fname
,
String
parameter set name
pname
,
byte[]
raw key bytes, not null
encoded
,
byte[]
expanded key format, can be null.
expanded
)

Creates a NamedPKCS8Key from raw components.

public boolean
isDestroyed()

Overrides default javax.security.auth.Destroyable.isDestroyed.

Determine if this Object has been destroyed.

private void
readObject(ObjectInputStream stream)

Hides sun.security.pkcs.PKCS8Key.readObject.

We used to serialize a PKCS8Key as itself (instead of a KeyRep).

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from sun.security.pkcs.PKCS8Key:
clearequalsgetAlgorithmIdgetEncodedgetEncodedgetFormatgetPubKeyEncodedgetVersionhashCodehasPublicKeyparseKeyparseKeywriteReplace

Field Detail

destroyedback to summary
private transient boolean destroyed
expandedback to summary
private final transient byte[] expanded
fnameback to summary
private final String fname
paramSpecback to summary
private final transient NamedParameterSpec paramSpec
serialVersionUIDback to summary
private static final long serialVersionUID

Hides sun.security.pkcs.PKCS8Key.serialVersionUID, java.security.PrivateKey.serialVersionUID.

Annotations
@Serial

Constructor Detail

NamedPKCS8Keyback to summary
private NamedPKCS8Key(String fname, String pname, byte[] encoded, byte[] expanded)

Creates a NamedPKCS8Key from raw components.

Parameters
fname:String

family name

pname:String

parameter set name

encoded:byte[]

raw key bytes, not null

expanded:byte[]

expanded key format, can be null.

NamedPKCS8Keyback to summary
public NamedPKCS8Key(String fname, byte[] encoded, NamedPKCS8Key.Expander expander) throws InvalidKeyException

Creates a NamedPKCS8Key from family name and PKCS #8 encoding.

Parameters
fname:String

family name

encoded:byte[]

PKCS #8 encoding. It is copied so caller can modify it after the method call.

expander:NamedPKCS8Key.Expander

a function that is able to calculate the expanded format from the encoding format inside encoded. If it recognizes the input already in expanded format, it must return null. This argument must be null if the algorithm's expanded format is always the same as its encoding format. Whatever the case, the ownership of the result is fully granted to this object.

Method Detail

destroyback to summary
public void destroy()

Overrides default javax.security.auth.Destroyable.destroy.

Doc from javax.security.auth.Destroyable.destroy.

Destroy this Object.

Sensitive information associated with this Object is destroyed or cleared. Subsequent calls to certain methods on this Object will result in an IllegalStateException being thrown.

Annotations
@Override
getAlgorithmback to summary
public String getAlgorithm()

Overrides sun.security.pkcs.PKCS8Key.getAlgorithm.

Implements java.security.Key.getAlgorithm.

Doc from sun.security.pkcs.PKCS8Key.getAlgorithm.

Returns the algorithm to be used with this key.

Annotations
@Override
getExpandedback to summary
public byte[] getExpanded()

Returns the reference to the key in expanded format. Caller must not modify the content or pass the reference to untrusted application code.

getParamsback to summary
public NamedParameterSpec getParams()

Overrides default java.security.AsymmetricKey.getParams.

Doc from java.security.AsymmetricKey.getParams.

Returns the parameters associated with this key. The parameters are optional and may be either explicitly specified or implicitly created during key pair generation.

Annotations
@Override
getRawBytesback to summary
public byte[] getRawBytes()

Returns the reference to the internal key. Caller must not modify the content or pass the reference to untrusted application code.

internalCreateback to summary
public static NamedPKCS8Key internalCreate(String fname, String pname, byte[] encoded, byte[] expanded)

Creates a NamedPKCS8Key from raw components.

encoded and expanded won't be cloned, caller must relinquish ownership. This caller must ensure encoded and expanded match each other and encoded is valid and internally-consistent.

Parameters
fname:String

family name

pname:String

parameter set name

encoded:byte[]

raw key bytes, not null

expanded:byte[]

expanded key format, can be null.

isDestroyedback to summary
public boolean isDestroyed()

Overrides default javax.security.auth.Destroyable.isDestroyed.

Doc from javax.security.auth.Destroyable.isDestroyed.

Determine if this Object has been destroyed.

Annotations
@Override
readObjectback to summary
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException

Hides sun.security.pkcs.PKCS8Key.readObject.

Doc from sun.security.pkcs.PKCS8Key.readObject.

We used to serialize a PKCS8Key as itself (instead of a KeyRep).

Annotations
@Serial
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
sun.security.pkcs back to summary

public Interface NamedPKCS8Key.Expander

Annotations
@FunctionalInterface

Expands from encoding format to expanded format.

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

the expanded key, null if input is already in expanded
expand
(String
parameter set name
pname
,
byte[]
input encoding
input
)

The expand method

Method Detail

expandback to summary
public byte[] expand(String pname, byte[] input) throws InvalidKeyException

The expand method

Parameters
pname:String

parameter set name

input:byte[]

input encoding

Returns:byte[]

the expanded key, null if input is already in expanded

Exceptions
InvalidKeyException:
if input is invalid, for example, wrong encoding, or internal inconsistency