APIdia Launch Partner
Top Description Fields Constructors Methods
java.security.spec

public abstract Class EncodedKeySpec

extends Object
implements KeySpec
Class Inheritance
All Implemented Interfaces
java.security.spec.KeySpec
Known Direct Subclasses
java.security.spec.PKCS8EncodedKeySpec, java.security.spec.X509EncodedKeySpec, sun.security.provider.NamedKeyFactory.RawEncodedKeySpec
Imports
jdk.internal.access.SharedSecrets, java.util.Arrays

This class represents a public or private key in encoded format.
Author
Jan Luehe
Since
1.2
See Also
java.security.Key, java.security.KeyFactory, KeySpec, X509EncodedKeySpec, PKCS8EncodedKeySpec

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
EncodedKeySpec(byte[]
the encoded key. The contents of the array are copied to protect against subsequent modification.
encodedKey
)

Creates a new EncodedKeySpec with the given encoded key.

protected
EncodedKeySpec(byte[]
the encoded key. The contents of the array are copied to protect against subsequent modification.
encodedKey
,
String
the algorithm name of the encoded key. See the AsymmetricKey Algorithms section in the Java Security Standard Algorithm Names Specification for information about standard asymmetric key algorithm names.
algorithm
)

Creates a new EncodedKeySpec with the given encoded key.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
clear()

Clear the encoding inside.

public String

Returns:

the name of the algorithm, or null if not specified
getAlgorithm
()

Returns the name of the algorithm of the encoded key.

public byte[]

Returns:

the encoded key. Returns a new array each time this method is called.
getEncoded
()

Returns the encoded key.

public abstract String

Returns:

a string representation of the encoding format.
getFormat
()

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmNameback to summary
private String algorithmName
encodedKeyback to summary
private final byte[] encodedKey

Constructor Detail

EncodedKeySpecback to summary
public EncodedKeySpec(byte[] encodedKey)

Creates a new EncodedKeySpec with the given encoded key.

Parameters
encodedKey:byte[]

the encoded key. The contents of the array are copied to protect against subsequent modification.

Exceptions
NullPointerException:
if encodedKey is null.
EncodedKeySpecback to summary
protected EncodedKeySpec(byte[] encodedKey, String algorithm)

Creates a new EncodedKeySpec with the given encoded key. This constructor is useful when subsequent callers of the EncodedKeySpec object might not know the algorithm of the key.

Parameters
encodedKey:byte[]

the encoded key. The contents of the array are copied to protect against subsequent modification.

algorithm:String

the algorithm name of the encoded key. See the AsymmetricKey Algorithms section in the Java Security Standard Algorithm Names Specification for information about standard asymmetric key algorithm names.

Exceptions
NullPointerException:
if encodedKey or algorithm is null.
IllegalArgumentException:
if algorithm is the empty string ""
Since
9
External Specification
Java Security Standard Algorithm Names

Method Detail

clearback to summary
pack-priv void clear()

Clear the encoding inside.

getAlgorithmback to summary
public String getAlgorithm()

Returns the name of the algorithm of the encoded key.

Returns:String

the name of the algorithm, or null if not specified

Since
9
getEncodedback to summary
public byte[] getEncoded()

Returns the encoded key.

Returns:byte[]

the encoded key. Returns a new array each time this method is called.

getFormatback to summary
public abstract String 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.

Returns:String

a string representation of the encoding format.